[Numpy-discussion] non-intuitive behaviour in numpy.array([list], numpy.object_)

2008-01-03 Thread Garnet Chan
When constructing an numpy object array from a list of numpy arrays, one observes the following behaviour import numpy as N a=[N.zeros([2,2], N.object_), N.zeros([2,2], N.object_)] b=N.array(a, N.object_) print b.shape (2, 2, 2) a=[N.zeros([2,2], N.object_), N.zeros([2,1], N.object_)]

Re: [Numpy-discussion] non-intuitive behaviour in numpy.array([list], numpy.object_)

2008-01-03 Thread Christopher Barker
Garnet Chan wrote: When constructing an numpy object array from a list of numpy arrays, one observes the following behaviour import numpy as N a=[N.zeros([2,2], N.object_), N.zeros([2,2], N.object_)] b=N.array(a, N.object_) print b.shape (2, 2, 2) a=[N.zeros([2,2], N.object_),

[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

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)

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

Re: [Numpy-discussion] non-intuitive behaviour in numpy.array([list], numpy.object_)

2008-01-03 Thread Garnet Chan
Thanks - that's clear I guess, although I still think that it might be less confusing if numpy did not try to be clever! On 1/3/08, Christopher Barker [EMAIL PROTECTED] wrote: Garnet Chan wrote: When constructing an numpy object array from a list of numpy arrays, one observes the following

[Numpy-discussion] MaskedArray and Record Arrays

2008-01-03 Thread Alexander Michael
I am experimenting with the new MaskedArray (from http://svn.scipy.org/svn/numpy/branches/maskedarray) as a replacement for my own home-brewed masked data handling mechanisms. In what I have built myself, I often work with record arrays that have a single mask for the whole record (no fieldmask).

[Numpy-discussion] MaskedArray and the min,max,sum,prod Methods

2008-01-03 Thread Alexander Michael
Working with the new MaskedArray, I noticed the following differences with numpy.array behavior: masked_array([1, 2, 3], mask=True).min() 2147483647 array([]).min() Traceback (most recent call last): File stdin, line 1, in module ValueError: zero-size array to ufunc.reduce without identity

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

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:

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

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

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

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,

Re: [Numpy-discussion] Numpy code coverage

2008-01-03 Thread Robert Kern
Stefan van der Walt wrote: Hi all, I read about Titus Brown's Figleaf code coverage tool [1] on the Planet SciPy aggregator [2]. The results of running figleaf on the numpy test-suite [3] covers Python code only. What the best way of discovering the C and C++ code coverage as well? I've

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.

[Numpy-discussion] Error importing from numpy.matlib

2008-01-03 Thread Steve Lianoglou
Hi all, I can't figure out why this is happening ... I just recently recompiled numpy/scipy from svn just for the heck of it. Anyway, somewhere in my codebase (for a long time now) I'm doing: from numpy.matlib import * Now, when I try to use this code, or just type that in the interpreter,

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

[Numpy-discussion] weird indexing

2008-01-03 Thread Mathew Yeates
Hi Okay, here's a weird one. In Fortran you can specify the upper/lower bounds of an array e.g. REAL A(3:7) What would be the best way to translate this to a Numpy array? I would like to do something like A=numpy.zeros(shape=(5,)) and have the expression A[3] actually return A[0]. Or