[Numpy-discussion] truthiness of object arrays

Alan G Isaac alan.isaac at gmail.com
Thu Nov 13 13:05:12 EST 2014

On 11/13/2014 12:37 PM, Antony Lee wrote:
> On Python3, __nonzero__ is never defined (always raises an AttributeError), even after calling __bool__.

The example I posted was Python 3.4.1 with numpy 1.9.0.

Alan Isaac

Python 3.4.1 (v3.4.1:c0e311e010fc, May 18 2014, 10:38:22) [MSC v.1600 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
 >>> import numpy as np
 >>> np.__version__
 >>> t = np.array(None); t[()] = np.array([None, None])
 >>> t.__nonzero__()
Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
AttributeError: 'numpy.ndarray' object has no attribute '__nonzero__'
 >>> t.__bool__()
 >>> t.__nonzero__()
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

More information about the NumPy-Discussion mailing list