micropython-ulab/tests/2d/numpy/vectorize.py
2023-01-04 00:27:41 +01:00

18 lines
334 B
Python

try:
from ulab import numpy as np
except:
import numpy as np
dtypes = (np.uint8, np.int8, np.uint16, np.int16, np.float)
square = np.vectorize(lambda n: n*n)
for dtype in dtypes:
a = np.array(range(9), dtype=dtype).reshape((3, 3))
print(a)
print(square(a))
b = a[:,2]
print(square(b))
print()