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

Andrew Straw strawman@astraw....
Fri Jan 4 13:27:34 CST 2008


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
zero-dimensional array is True, so the following holds and illustrates
how the above result is consistent with numpy's rules.



Andrew Straw wrote:
> Apologies if I've missed the discussion of this, but I was recently
> surprised by the following behavior (in svn trunk 4673). The following
> code runs without triggering the assertion.
> 
> import numpy as np
> print np.__version__
> a=np.int32(42)
> b=np.array([],dtype=np.int32)
> assert np.allclose(a,b)
> 
> Is this expected behavior of numpy or is this a bug I should report?
> 
> Thanks,
> Andrew
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion@scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion



More information about the Numpy-discussion mailing list