I'm looking for information or libraries with 2D arrays/matrix implementation, unfortunately i have been searching
on the forum also on git-hub repos and I have not found anything similar to Python Numpy ( where arrays.matrix operation are base on
LAPACK/BLAS interface ), micropython array.array is simple and do not even cover to create 2D array.
Does anyone present on the forum has encountered this problem and maybe found solution?
2D Arrays/Matrix in micropython
Re: 2D Arrays/Matrix in micropython
Sounds like you're looking for ulab -- https://github.com/v923z/micropython-ulab/
Re: 2D Arrays/Matrix in micropython
From what I can tell, there isn't a direct equivalent to the NumPy library for MicroPython. However, there are some workarounds that you can use to get similar functionality. One workaround is to use the built-in array and bytearray types. You can use these types to create two-dimensional arrays and then use the methods from the array module to perform operations on them.
Another workaround is to use the uarray module. This module provides an efficient way to create and manipulate NumPy-like arrays. The uarray module is not part of the standard MicroPython distribution, so you will need to install it using the upip tool.
Once you have installed the uarray module, you can use it to create and manipulate NumPy-like arrays. The following code snippet shows an example of how to create a two-dimensional array and perform some operations on it:
You can find more information about the uarray module in the MicroPython documentation: https://docs.micropython.org/en/v1.14/l ... array.html
Another workaround is to use the uarray module. This module provides an efficient way to create and manipulate NumPy-like arrays. The uarray module is not part of the standard MicroPython distribution, so you will need to install it using the upip tool.
Once you have installed the uarray module, you can use it to create and manipulate NumPy-like arrays. The following code snippet shows an example of how to create a two-dimensional array and perform some operations on it:
Code: Select all
import uarray
a = uarray.zeros((10, 10))
a[0, 0] = 1
a[1, 1] = 2
a[2, 2] = 3
print(a)
# Output:
# [[1 0 0 0 0 0 0 0 0 0]
# [0 2 0 0 0 0 0 0 0 0]
# [0 0 3 0 0 0 0 0 0 0]
# [0 0 0 0 0 0 0 0 0 0]
# [0 0 0 0 0 0 0 0 0 0]
# [0 0 0 0 0 0 0 0 0 0]
# [0 0 0 0 0 0 0 0 0 0]
# [0 0 0 0 0 0 0 0 0 0]
# [0 0 0 0 0 0 0 0 0 0]
# [0 0 0 0 0 0 0 0 0 0]]
b = uarray.ones((10, 10))
print(b)
# Output:
# [[1 1 1 1 1 1 1 1 1 1]
# [1 1 1 1 1 1 1 1 1 1]
# [1 1 1 1 1 1 1 1 1 1]
# [1 1 1 1 1 1 1 1 1 1]
# [1 1 1 1 1 1 1 1 1 1]
# [1 1 1 1 1 1 1 1 1 1]
# [1 1 1 1 1 1 1 1 1 1]
# [1 1 1 1 1 1 1 1 1 1]
# [1 1 1 1 1 1 1 1 1 1]
# [1 1 1 1 1 1 1 1 1 1]]
c = a + b
print(c)
# Output:
# [[2 1 1 1 1 1 1 1 1 1]
# [1 3 1 1 1 1 1 1 1 1]
# [1 1 4 1 1 1 1 1 1 1]
# [1 1 1 1 1 1 1 1 1 1]
# [1 1 1 1 1 1 1 1 1 1]
# [1 1 1 1 1 1 1 1 1 1]
# [1 1 1 1 1 1 1 1 1 1]
# [1 1 1 1 1 1 1 1 1 1]
# [1 1 1 1 1 1 1 1 1 1]
# [1 1 1 1 1 1 1 1 1 1]]
Last edited by jameswise on Tue Aug 16, 2022 10:36 am, edited 1 time in total.
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: 2D Arrays/Matrix in micropython
@jameswise That documentation link is incorrect.
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
Re: 2D Arrays/Matrix in micropython
This is exactly what i need and even more - Thanks!jimmo wrote: ↑Sat Aug 13, 2022 2:33 pmSounds like you're looking for ulab -- https://github.com/v923z/micropython-ulab/
jameswise - thanks for explanation - I'm going to use arrays/matrix in dsp processing and micropython array/uarray is not applicable for this, and uarray ( did You meant: ( https://uarray.org/en/latest/ , https://github.com/Quansight-Labs/uarray ?? ) - > is a python build.
- OlivierLenoir
- Posts: 126
- Joined: Fri Dec 13, 2019 7:10 pm
- Location: Picardie, FR
Re: 2D Arrays/Matrix in micropython
MicroPython - Matrix, basic matrix operations, using list. The project is available here.
Olivier Lenoir
https://gitlab.com/olivierlenoir
https://gitlab.com/olivierlenoir