Doing a = in Python will simply restore the local variable a ; it will not affect what a contains.
With nditer , the iteration variables a1 , a2 and a are actually 0-d arrays. Thus, to change a , use the syntax (slightly odd) a[()] = :
for a1, a2, a in it: a[()] = a1 if -a1 < a2 else a2
Note, however, that all of your code can be simplified using np.where :
import numpy as np arr1 = - np.random.random((2,2)) arr2 = np.random.random((2,2)) arr = np.where(-arr1 < arr2, arr1, arr2)
source share