Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

REQUIRES PYTHON3.1
test usage: python3.1 setup.py build dev --quicktest
bytearray numerical extension

EXAMPLE USAGE:

$ python3.1
Python 3.1.1 (r311:74480, Sep 13 2009, 17:17:12)
[GCC 4.3.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from numbytes import *

>>> ## create bytearray of 3x4 matrix of int64
>>> bytes_integer = numbytes("i", range(12), shape0=3, shape1=4)
>>> bytes_integer.debug()
<class 'numbytes.numbytes'> i refcnt=4 tsize=8 shape=<3 4> strides=<4 1> transposed=0

>>> ## underlying bytearray object
>>> print(bytes_integer.bytes)
bytearray(b'\x00\x00\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(bytes_integer)
[[ 0 1 2 3]
[ 4 5 6 7]
[ 8 9 10 11]]

>>> ## slice
>>> print(bytes_integer[1:, 2:])
[[ 6 7]
[ 10 11]]

>>> ## transpose
>>> print(bytes_integer.T)
[[ 0 4 8]
[ 1 5 9]
[ 2 6 10]
[ 3 7 11]]

>>> print(bytes_integer.T[1:, 2:])
[[ 9]
[ 10]
[ 11]]

>>> ## recast into double type
>>> bytes___float = bytes_integer.recast("f") / 3
>>> print(bytes___float)
[[ 0 0.333333 0.666667 1]
[ 1.33333 1.66667 2 2.33333]
[ 2.66667 3 3.33333 3.66667]]

>>> ## most arithmetic operations are inplace
>>> ## use copy to avoid side-effects
>>> print(bytes_integer.copy[1:, 2:] + bytes___float.copy[1:, 2:])
[[ 8 9]
[ 13 14]]

>>> print(bytes___float.copy[1:, 2:] + bytes_integer.copy[1:, 2:])
[[ 8 9.33333]
[ 13.3333 14.6667]]

>>> print(bytes_integer.copy & bytes___float.copy)
[[ 0 0 0 1]
[ 0 1 2 2]
[ 0 1 2 3]]

>>> ## illegal bitwise operation on double
>>> print(bytes___float.copy & bytes_integer.copy)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ArithmeticError: cannot <double &= double>

RECENT CHANGE:
20091205 - moved source code to c++
20091116 - package integrated
20081219
- tobias rodaebel points out ".." is used in relative imports as well.
fixed pseudomethod 2 be compatible w/ this
- removed limitation where parser disallows use of keyword "__pseudomethod__"
in scripts

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

numbytes-2009.12.06.py3k.cpp.static.tar.gz (83.0 kB view details)

Uploaded Source

File details

Details for the file numbytes-2009.12.06.py3k.cpp.static.tar.gz.

File metadata

File hashes

Hashes for numbytes-2009.12.06.py3k.cpp.static.tar.gz
Algorithm Hash digest
SHA256 bf31a1f91cef46bffa5475e06b1dc7fc1c3f15224e5bb922eab8f0fc7817575e
MD5 0d2f3f77b2e155ae5db98fc912acae9f
BLAKE2b-256 5a1fd118789def14aae564f05a610ee4bdbb4cff234eb8c3c739ffdc444f74cb

See more details on using hashes here.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page