[Numpy-discussion] unexpected behavior with allclose( scalar, empty array)

Andrew Straw strawman@astraw....
Fri Jan 4 15:00:39 CST 2008


Thanks, I updated the page.

Charles R Harris wrote:
>
>
> On Jan 4, 2008 12:27 PM, Andrew Straw <strawman@astraw.com
> <mailto: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
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion@scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion
>   



More information about the Numpy-discussion mailing list