[Numpy-discussion] truthiness of object arrays
Antony Lee
antony.lee at berkeley.edu
Tue Nov 11 15:46:44 EST 2014
I am puzzled by the following (numpy 1.9.0, python 3.4.2):
In [1]: t = array(None); t[()] = array([None, None]) # Construct a 0d
array of dtype object, containing a single numpy array with 2 elements
In [2]: bool(t)
Out[2]: True
In [3]: if t: pass
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
ValueError: The truth value of an array with more than one element is
ambiguous. Use a.any() or a.all()
I thought that "if x" simply calls "bool", but apparently this is not even
the case...
Antony
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20141111/169a5ba5/attachment.html>
More information about the NumPy-Discussion
mailing list