[NumPy-Tickets] [NumPy] #1433: numpy array captures 'in' statement when it shouldn't

NumPy Trac numpy-tickets@scipy....
Sun Sep 5 13:51:04 CDT 2010

#1433: numpy array captures 'in' statement when it shouldn't
  Reporter:  graik       |       Owner:  somebody    
      Type:  defect      |      Status:  closed      
  Priority:  normal      |   Milestone:              
 Component:  numpy.core  |     Version:  1.3.0       
Resolution:  wontfix     |    Keywords:  __contains__
Changes (by pv):

  * status:  new => closed
  * resolution:  => wontfix


 That has not worked in any Numpy versions:
 >>> import numpy as np
 >>> np.__version__
 >>> a = np.arange(10); a in (0, None)
 Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
 ValueError: The truth value of an array with more than one element is
 ambiguous. Use a.any() or a.all()
 Perhaps you mean it used to work in Numeric. However, even there it did
 not do what you would think:
 >>> import Numeric
 >>> a = Numeric.arange(10)
 >>> a in (0, None)

 The point why `__contains__` is ambiguous is that the equality operation
 on arrays is defined to return a boolean array of elementwise comparisons,
 and it is ambiguous if the result should be reduced to a single boolean
 via `all()` or via `any()`.

 It is not possible to special-case for `__contains__` due to the way
 Python implements it.

Ticket URL: <http://projects.scipy.org/numpy/ticket/1433#comment:1>
NumPy <http://projects.scipy.org/numpy>
My example project

More information about the NumPy-Tickets mailing list