micropython-numpy
is a numpy-like array manipulation library for micropython.
The module is written in C and aims to provide as much compatibility as possible with select core numpy functionality.
This beginnings of this project were heavily inspired by the ulab project. In its current version however, virtually all functionality has been redesigned from the ground up to handle multidimensional arrays and array views.
Documentation is very lacking at the moment but a user familiar with numpy should be able to infer the syntax from the current numpy documentation.
One major difference is that shape
and ndim
and size
are not properties but methods.
The reason for that is discussed here.
In order to make your code run on both the micropython as well as the regular python
numpy use the functions np.shape
, np.ndim
, and np.shape
, instead, which are present
in both versions. For example, instead of
a = np.array([1,2,3])
shape = a.shape
use
a = np.array([1,2,3])
shape = np.shape(a)
The property a.shape
works only on regular numpy and the method a.shape()
works
only on micropython.
- Multidimensional arrays
- Support types:
- bool_, uint8, int8, uint16, int16, float_
- Slices are fully supported as views
- Unary + binary operators
- all but inplace operators
- Functions and methods:
max
,min
,all
,any
,sum
,prod
minimum
,maximum
concatenate
,vstack
,hstack
empty
,full
,zeros
,ones
,eye
flip
,fliplr
,flipud
- Supported float functions:
acos
,asin
,atan
,sin
,cos
,tan
acosh
,asinh
,atanh
,sinh
,cosh
,tanh
ceil
,floor
erf
,erfc
exp
,expm1
gamma
,lgamma
log
,log10
,log2
sqrt
- Linear algebra
dot
lu
,solve
,inv
,det
- Extensive unittest based routines
- Advanced indexing
- uint32/int32/complex types
- Inplace operators
- @ operator
- Lots of linear algebra
Compile as a regular micropython external C module. At this time you will need to use the following fork and branch
https://github.com/ComplexArts/micropython/tree/equality
to fix some micropython issues have with equality. See this PR for details on this issue.