[Numpy-discussion] unexpected behavior with allclose( scalar, empty array)
Charles R Harris
charlesr.harris@gmail....
Fri Jan 4 13:57:51 CST 2008
On Jan 4, 2008 12:27 PM, Andrew Straw <strawman@astraw.com> wrote:
> I have added a page to the wiki describing this issue:
>
> http://scipy.org/numpy_warts_and_gotchas
>
> I'll link it into the main documentation pages over the next few days,
> but I ask for a review the following text for correctness and clarity:
> (You can simply edit the wiki page or post your reply here and I'll do
> it.)
>
> Like most of numpy, allclose() uses the broadcasting rules when
> performing its operation. This leads to the following behavior:
>
> >>> a=32
> >>> b=numpy.array([])
> >>> numpy.allclose(a,b)
> True
>
> Upon closer inspection, we can see that the broadcasting rules cause a
> to become a zero-dimensional array like b. The default truth value of a
It is not the dimensions, it's the fact that the array is empty, so that
anything said about it's non-existent elements is true, i.e., x in empty ->
anything is always true because x in empty is always false. So we also have
the following:
In [1]: allclose(32,[[]])
Out[1]: True
The other reason is that because of broadcasting, the shape of the arrays
may be immaterial.
Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/numpy-discussion/attachments/20080104/e40d99fc/attachment.html
More information about the Numpy-discussion
mailing list