2010/8/27 Brett Olsen <brett.ol...@gmail.com>:
> If there's multiple possible valid values, I've come up with a couple
> possible methods, but they all seem to be inefficient or kludges:
>>>> valid = N.array(("a", "c"))
>>>> (ar == valid[0]) | (ar == valid[1])
> array([ True, False,  True, False, False,  True, False,  True,  True],
> dtype=bool)
>>>> N.array(map(lambda x: x in valid, ar))
> array([ True, False,  True, False, False,  True, False,  True,  True],
> dtype=bool)

(ar[..., numpy.newaxis] == valid).T.sum(axis=0).T > 0

should also do the job.  But it eats up memory.  (It employs broadcasting.)

Friedrich
_______________________________________________
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion

Reply via email to