[Numpy-discussion] More about booleans as indices

Pierre GM pgmdevlist at mailcan.com
Tue Mar 28 00:19:06 CST 2006


Folks,
I was playing with the compress method and extended slicing techniques, when I 
ran into this problem:
I want to select the records of rec.array (`arec`) for which a given tag 
(`tag`) has some given values, as listed in `specialtaglist`.
A basic
arec[arec.tag in specialtaglist]
raises a ValueError exception (ValueError: The truth value of an array with 
more than one element is ambiguous. Use a.any() or a.all()). A workaround I 
found was:
arec[ [arec.tag[k] in specialtaglist for k in range(len(arec))] ]

I was wondering whether there was a better/faster/simpler method ?
Thx in advance




More information about the Numpy-discussion mailing list