[Numpy-discussion] Quick array value assignment based on common values

Sturla Molden sturla@molden...
Wed Aug 4 19:55:28 CDT 2010


> Is there a concise, Numpythonic way to copy the values of x[:,1] over to
> y[:,1] where x[:,0] = y[:,0]? Resulting in, z:

First use

   mask = (x[:,0] == y[:,0]) # integers

or

   mask = np.abs(x[:,0] - y[:,0]) < eps # floats

and then

   y[mask,1] = x[mask,1]


Sturla



More information about the NumPy-Discussion mailing list