<div dir="ltr">On Python3, __nonzero__ is never defined (always raises an AttributeError), even after calling __bool__.</div><div class="gmail_extra"><br><div class="gmail_quote">2014-11-13 5:24 GMT-08:00 Alan G Isaac <span dir="ltr"><<a href="mailto:alan.isaac@gmail.com" target="_blank">alan.isaac@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On 11/13/2014 1:19 AM, Antony Lee wrote:<br>
> "t.__bool__()" also returns True<br>
<br>
<br>
But t.__nonzero__() is being called in the `if` test.<br>
The question is: is the difference between `__nonzero__`<br>
and `__bool__` intentional.<br>
<br>
By the way, there has been a change in behavior.<br>
For example, in 1.7.1 if you call `t.__bool__()`<br>
it raised an attribute error -- unless one first<br>
called `t.__nonzero__()` and then called `t.__bool__()`,<br>
which was of course very weird and needed to be fixed.<br>
Maybe (?) not like this.<br>
<br>
In fact the oddity probably remains but moved. in 1.9.0 I see this:<br>
<br>
 >>> np.__version__<br>
'1.9.0'<br>
 >>> t = np.array(None); t[()] = np.array([None, None])<br>
 >>> t.__nonzero__()<br>
Traceback (most recent call last):<br>
   File "<stdin>", line 1, in <module><br>
AttributeError: 'numpy.ndarray' object has no attribute '__nonzero__'<br>
 >>> t.__bool__()<br>
True<br>
 >>> t.__nonzero__()<br>
<span class="im HOEnZb">ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()<br>
<br>
</span><span class="HOEnZb"><font color="#888888">Alan Isaac<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
<br>
_______________________________________________<br>
NumPy-Discussion mailing list<br>
<a href="mailto:NumPy-Discussion@scipy.org">NumPy-Discussion@scipy.org</a><br>
<a href="http://mail.scipy.org/mailman/listinfo/numpy-discussion" target="_blank">http://mail.scipy.org/mailman/listinfo/numpy-discussion</a><br>
</div></div></blockquote></div><br></div>