How to apply transformation function to each element in NumPy array with Python

1 Answer

0 votes
import numpy as np

arr = np.array((0, 5, 10, 15))

transformed = np.array(list(map(lambda x: np.array((x, x * 2, x * 3)), arr)))

print(transformed)
print(transformed.shape)


'''
run:
 
[[ 0  0  0]
 [ 5 10 15]
 [10 20 30]
 [15 30 45]]
(4, 3)

'''

 



answered Mar 22 by avibootz
edited Mar 22 by avibootz
...