[Numpy-discussion] strange behavior with a numpy array as member of a list

Tim Hirzel hirzel at resonon.com
Thu Nov 30 13:53:19 CST 2006


Hi All,
When a list contains a numpy array and I want to see if a value is a 
member of that list, I can get a value error from numpy:

 >>> import numpy
 >>> numpy.__version__
'1.0'
 >>> a = numpy.arange(10)
 >>> L = [a]
 >>> a in L
True
 >>> 2 in L
Traceback (most recent call last):
 File "<input>", line 1, in ?
ValueError: The truth value of an array with more than one element is 
ambiguous. Use a.any() or a.all()

 >>> L = [2, a]  #just to illuminate the scenario a little more
 >>> 2 in L
True

Does this seem odd to anyone else?  I am not sure about the 
implementation of 'in' but it seems like a comparison is going funny 
somewhere.  Or I am missing something...

thanks!
tim


More information about the Numpy-discussion mailing list