truthiness of object arrays
11 Nov
2014
11 Nov
'14
8:46 p.m.
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
3422
Age (days ago)
3425
Last active (days ago)
11 comments
6 participants
participants (6)
-
Alan G Isaac
-
Antony Lee
-
Charles R Harris
-
Michael Sarahan
-
Nathaniel Smith
-
Sebastian Berg