[Numpy-discussion] [Q]Best way for an array operation?

Janko Hauser jhauser at ifm.uni-kiel.de
Fri Oct 13 18:13:23 CDT 2000


You do not define, what values are in z,y if x < 0, so I presume, they
keep the current value.


>>> true = greater(x,0.)
>>> z=where(true, u+2., z)
>>> y=where(true, v, y)

HTH,
__Janko

Daehyok Shin writes:
 > What is the best Numpy way for the following work?
 > 
 > for i in range(len(x)):
 >     if x[i] > 0:
 >         y[i] = v[i]
 >         z[i] = u[i]+2
 > 
 > Daehyok Shin (Peter)
 > 
 > 
 > _______________________________________________
 > Numpy-discussion mailing list
 > Numpy-discussion at lists.sourceforge.net
 > http://lists.sourceforge.net/mailman/listinfo/numpy-discussion



More information about the Numpy-discussion mailing list