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

2008-01-04 Thread Charles R Harris
On Jan 4, 2008 12:27 PM, Andrew Straw [EMAIL PROTECTED] 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


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

2008-01-04 Thread Andrew Straw
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

___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


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

2008-01-04 Thread Andrew Straw
Thanks, I updated the page.

Charles R Harris wrote:


 On Jan 4, 2008 12:27 PM, Andrew Straw [EMAIL PROTECTED]
 mailto:[EMAIL PROTECTED] 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
   

___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


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

2008-01-03 Thread Andrew Straw
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


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

2008-01-03 Thread Robert Kern
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?

Bug, I think.

-- 
Robert Kern

I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth.
  -- Umberto Eco
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


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

2008-01-03 Thread Charles R Harris
On Jan 3, 2008 1:06 PM, Robert Kern [EMAIL PROTECTED] wrote:

 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?

 Bug, I think.


Isn't it trivially true that all elements of an empty array are close to any
number? For instance, it is a well known fact that all blue, cheese eating
martians speak esperanto.

Chuck
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


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

2008-01-03 Thread Alan G Isaac
On Thu, 3 Jan 2008, Charles R Harris apparently wrote:
 Isn't it trivially true that all elements of an empty 
 array are close to any number? 

Sure, but might not one expect a ValueError due to
shape mismatch?  (Doesn't allclose usually use
normal broadcasting rules?)

Cheers,
Alan Isaac



___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


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

2008-01-03 Thread Matthew Brett
Hi,

   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?
 
  Bug, I think.

I think this bug - which may be mine - follows from this line in allclose:

return all(less_equal(absolute(x-y), atol + rtol * absolute(y)))

and:

In [39]: all([])
Out[39]: True

Matthew
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


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

2008-01-03 Thread Alan G Isaac
 On Thu, 3 Jan 2008, Charles R Harris apparently wrote:
 Isn't it trivially true that all elements of an empty 
 array are close to any number? 

On Thu, 3 Jan 2008, Alan G Isaac apparently wrote:
 Sure, but might not one expect a ValueError due to 
 shape mismatch?  (Doesn't allclose usually use 
 normal broadcasting rules?)

Ooops, forgot that was a scalar, so it was normal:

 a*b
array([], dtype=int32)

Cheers,
Alan Isaac




___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


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

2008-01-03 Thread Matthew Brett
Just to ask - is there a reason why this:

 In [39]: all([])
 Out[39]: True

is the case?
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


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

2008-01-03 Thread Charles R Harris
On Jan 3, 2008 2:37 PM, Matthew Brett [EMAIL PROTECTED] wrote:

 Just to ask - is there a reason why this:

  In [39]: all([])
  Out[39]: True

 is the case?


Because it's True. Anything is true about the elements of an empty set,
because there aren't any. In this case, all asks if all elements in [] are
true, i.e., does x member [] - x is true. Since x member [] is always
false, the implication is always true. Recall that the statement x - y has
the same truth value as the statement x' or xy.

Chuck
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


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

2008-01-03 Thread Matthew Brett
So, currently we have all and allclose giving the same answer:

In [19]: a = array([])

In [20]: b = array([1])

In [21]: all(a == b)
Out[21]: True

In [22]: allclose(a, b)
Out[22]: True

Would we want the answers to be different?
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


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

2008-01-03 Thread Robert Kern
Matthew Brett wrote:
 So, currently we have all and allclose giving the same answer:
 
 In [19]: a = array([])
 
 In [20]: b = array([1])
 
 In [21]: all(a == b)
 Out[21]: True
 
 In [22]: allclose(a, b)
 Out[22]: True
 
 Would we want the answers to be different?

No. I wasn't thinking correctly, previously.

-- 
Robert Kern

I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth.
  -- Umberto Eco
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


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

2008-01-03 Thread Matthew Brett
  So, currently we have all and allclose giving the same answer:
 
  In [19]: a = array([])
 
  In [20]: b = array([1])
 
  In [21]: all(a == b)
  Out[21]: True
 
  In [22]: allclose(a, b)
  Out[22]: True
 
  Would we want the answers to be different?

 No. I wasn't thinking correctly, previously.

It's unfortunate that all of us immediately think the given answer is wrong.
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


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

2008-01-03 Thread Andrew Straw
Matthew Brett wrote:
 So, currently we have all and allclose giving the same answer:

 In [19]: a = array([])

 In [20]: b = array([1])

 In [21]: all(a == b)
 Out[21]: True

 In [22]: allclose(a, b)
 Out[22]: True

 Would we want the answers to be different?
   
 No. I wasn't thinking correctly, previously.
 

 It's unfortunate that all of us immediately think the given answer is wrong.
Maybe we need allclose_sameshape() (my ability to name stuff is
terrible, but you get the idea). Regardless of the name issue, I have no
idea how this is viewed against the no-namespace-bloat principle.
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion