np.nditer
>>> def iter_add(x, y, out=None):
... addop = np.add
... it = np.nditer([x, y, out], [],
... [['readonly'], ['readonly'], ['writeonly','allocate']])
... with it:
... while not it.finished:
... addop(it[0], it[1], out=it[2])
... it.iternext()
... return it.operands[2]
3.71
7
import numpy as np
a=np.array([2,4,5])
print("Original array is :")
print(a)
print("Modified array is:")
for x in np.nditer(a):
print(x)
Thank you!
7
0
Are there any code examples left?
New code examples in category Python