Welcome, guest | Sign In | My Account | Store | Cart

Notice! PyPM is being replaced with the ActiveState Platform, which enhances PyPM’s build and deploy capabilities. Create your free Platform account to download ActivePython or customize Python with the packages you require and get automatic updates.

Download
ActivePython

numbytes is unavailable in PyPM, because there aren't any builds for it in the package repositories. Click the linked icons to find out why.

 Python 2.7Python 3.2Python 3.3
Windows (32-bit)
2009.12.24.py3k.cpp Failed View build log
2009.12.24.py3k.cpp Failed View build log
Windows (64-bit)
2009.12.24.py3k.cpp Failed View build log
2009.12.24.py3k.cpp Failed View build log
Mac OS X (10.5+)
2009.12.24.py3k.cpp Failed View build log
2009.12.24.py3k.cpp Failed View build log
Linux (32-bit)
2009.12.24.py3k.cpp Failed View build log
2009.12.24.py3k.cpp Failed View build log
Linux (64-bit)
2009.12.24.py3k.cpp Failed View build log
2009.12.24.py3k.cpp Failed View build log
2009.12.24.py3k.cpp Failed View build log
 
Links
Author
License
gpl
Lastest release
version 2009.12.24.py3k.cpp on Jan 5th, 2011

numerical bytearray - extends bytearray into numpy-like, 2d array

REQUIRES PYTHON3.1

QUICK TEST: $ python3.1 setup.py build dev --quicktest

DESCRIPTION: numerical bytearray - extends bytearray into numpy-like, 2d array

RECENT CHANGELOG: 20091224 - modularized package - fix install issues - added sdist check 20091209 - improved documentation 20091205 - moved source code to c++ 20091116 - package integrated

DEMO USAGE:

>>> from numbytes import *
>>> ## subclass numbytes
>>> class numbytes2(numbytes): pass
>>> ## create bytearray containing 3x4 array of longlong
>>> integers = numbytes2('i', range(12), shape0 = 3, shape1 = 4)
>>> print( integers.debug() )
<class 'numbytes.numbytes2'> i refcnt=4 tcode=i tsize=8 offset=0 shape=<3 4> stride=<4 1> transposed=0
[[          0           1           2           3]
[          4           5           6           7]
[          8           9          10          11]]
>>> ## modify underlying bytearray
>>> integers.bytes()[0] = 0xff; integers.bytes()[1] = 0xff
>>> print( integers.bytes() )
bytearray(b'\xff\xff\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x05\x00\x00\x00\x00\x00\x00\x00\x06\x00\x00\x00\x00\x00\x00\x00\x07\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\t\x00\x00\x00\x00\x00\x00\x00\n\x00\x00\x00\x00\x00\x00\x00\x0b\x00\x00\x00\x00\x00\x00\x00')
>>> print( integers.debug() )
<class 'numbytes.numbytes2'> i refcnt=4 tcode=i tsize=8 offset=0 shape=<3 4> stride=<4 1> transposed=0
[[      65535           1           2           3]
[          4           5           6           7]
[          8           9          10          11]]
>>> ## bytearray as sequence
>>> print( 2 in integers )
True
>>> print( integers.count(2) )
1
>>> print( integers.index(2) )
2
>>> for aa in integers.rows(): print( aa )
[[      65535           1           2           3]]
[[          4           5           6           7]]
[[          8           9          10          11]]
>>> ## slice
>>> print( integers[1:, 2:].debug() )
<class 'numbytes.numbytes2'> i refcnt=3 tcode=i tsize=8 offset=6 shape=<2 2> stride=<4 1> transposed=0
[[          6           7]
[         10          11]]
>>> ## transpose
>>> print( integers.T()[2:, 1:].debug() )
<class 'numbytes.numbytes2'> i refcnt=3 tcode=i tsize=8 offset=6 shape=<2 2> stride=<1 4> transposed=1
[[          6          10]
[          7          11]]
>>> ## reshape
>>> print( integers.reshape(2, -1).debug() )
<class 'numbytes.numbytes2'> i refcnt=3 tcode=i tsize=8 offset=0 shape=<2 6> stride=<6 1> transposed=0
[[      65535           1           2           3           4           5]
[          6           7           8           9          10          11]]
>>> ## setslice
>>> integers.T()[2:, 1:] = range(4); print( integers )
[[      65535           1           2           3]
[          4           5           0           2]
[          8           9           1           3]]
>>> ## almost all arithmetic operations are inplace - use copy to avoid side-effects
>>> ## recast to double
>>> floats = integers.recast('f') / 3; print( floats )
[[        21845      0.333333      0.666667             1]
[      1.33333       1.66667             0      0.666667]
[      2.66667             3      0.333333             1]]
>>> ## copy
>>> print( floats.copy() + integers[0, :] )
[[        87380       1.33333       2.66667             4]
[      65536.3       2.66667             2       3.66667]
[      65537.7             4       2.33333             4]]
>>> ## inplace
>>> print( floats + integers[:, 0] )
[[        87380       65535.3       65535.7         65536]
[      5.33333       5.66667             4       4.66667]
[      10.6667            11       8.33333             9]]
>>> ## inplace
>>> print( floats - integers[:, 0] )
[[        21845      0.333333      0.666667             1]
[      1.33333       1.66667             0      0.666667]
[      2.66667             3      0.333333             1]]
>>> ## inplace
>>> print( floats ** 2 )
[[  4.77204e+08      0.111111      0.444444             1]
[      1.77778       2.77778             0      0.444444]
[      7.11111             9      0.111111             1]]
>>> ## inplace
>>> print( floats.sqrt() )
[[        21845      0.333333      0.666667             1]
[      1.33333       1.66667             0      0.666667]
[      2.66667             3      0.333333             1]]
>>> ## the only inplace exceptions are logical comparisons, which return new char arrays
>>> print( floats )
[[        21845      0.333333      0.666667             1]
[      1.33333       1.66667             0      0.666667]
[      2.66667             3      0.333333             1]]
>>> ## copy as char
>>> print( floats == floats[:, 1] )
[[ 00  01  00  00]
[ 00  01  00  00]
[ 00  01  00  00]]
>>> ## copy as char
>>> print( floats > 1.5 )
[[ 01  00  00  00]
[ 01  01  00  00]
[ 01  01  00  00]]

Subscribe to package updates

Last updated Jan 5th, 2011

What does the lock icon mean?

Builds marked with a lock icon are only available via PyPM to users with a current ActivePython Business Edition subscription.

Need custom builds or support?

ActivePython Enterprise Edition guarantees priority access to technical support, indemnification, expert consulting and quality-assured language builds.

Plan on re-distributing ActivePython?

Get re-distribution rights and eliminate legal risks with ActivePython OEM Edition.