Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/wadetb/tinynumpy
A lightweight, pure Python, numpy compliant ndarray class.
https://github.com/wadetb/tinynumpy
Last synced: 11 days ago
JSON representation
A lightweight, pure Python, numpy compliant ndarray class.
- Host: GitHub
- URL: https://github.com/wadetb/tinynumpy
- Owner: wadetb
- License: other
- Created: 2014-11-06T02:58:20.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2020-07-31T03:00:53.000Z (over 4 years ago)
- Last Synced: 2024-10-01T21:48:25.522Z (about 1 month ago)
- Language: Python
- Homepage:
- Size: 153 KB
- Stars: 193
- Watchers: 14
- Forks: 35
- Open Issues: 18
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
tinynumpy
=========A lightweight, pure Python, numpy compliant ndarray class.
This module is intended to allow libraries that depend on numpy, but
do not make much use of array processing, to make numpy an optional
dependency. This might make such libaries better available, also on
platforms like Pypy and Jython.Links
-----* Github: https://github.com/wadetb/tinynumpy
* Docs: http://tinynumpy.readthedocs.org/en/latest/Features
--------* The ndarray class has all the same properties as the numpy ndarray
class.
* Pretty good compliance with numpy in terms of behavior (such as views).
* Can be converted to a numpy array (with shared memory).
* Can get views of real numpy arrays (with shared memory).
* Support for wrapping ctypes arrays, or provide ctypes pointer to data.
* Pretty fast for being pure Python.
* Works on Python 2.5+, Python 3.x, Pypy and Jython.Caveats
-------* ndarray.flat iterator cannot be indexed (it is a generator).
* No support for Fortran order.
* Support for data types limited to bool, uin8, uint16, uint32, uint64,
int8, int16, int32, int64, float32, float64.
* Functions that calculate statistics on the data are much slower, since
the iteration takes place in Python.
* Assigning via slicing is usually pretty fast, but can be slow if the
striding is unfortunate.Examples
--------```python
>>> from tinynumpy import tinynumpy as tnp
>>> a = tnp.array([[1, 2, 3, 4],[5, 6, 7, 8]])
>>> a
array([[ 1., 2., 3., 4.],
[ 5., 6., 7., 8.]], dtype='float64')>>> a[:, 2:]
array([[ 3., 4.],
[ 7., 8.]], dtype='float64')>>> a[:, ::2]
array([[ 1., 3.],
[ 5., 7.]], dtype='float64')>>> a.shape
(2, 4)>>> a.shape = 4, 2
>>> a
array([[ 1., 2.],
[ 3., 4.],
[ 5., 6.],
[ 7., 8.]], dtype='float64')>>> b = a.ravel()
>>> a[0, 0] = 100
>>> b
array([ 100., 2., 3., 4., 5., 6., 7., 8.], dtype='float64')
```