Tinynumpy
A lightweight, pure Python, numpy compliant ndarray class.
Install / Use
/learn @wadetb/TinynumpyREADME
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
>>> 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')
Related Skills
node-connect
338.0kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
83.4kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
338.0kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
commit-push-pr
83.4kCommit, push, and open a PR
