Re: [Numpy-discussion] Matching 0-d arrays and NumPy scalars

2008-02-22 Thread Lisandro Dalcin
Travis, after reading all the post on this thread, my comments Fist of all, I'm definitelly +1 on your suggestion. Below my rationale. * I believe numpy scalars should provide all possible features needed to smooth the difference between mutable, indexable 0-d arrays and inmutable, non-indexable

Re: [Numpy-discussion] Matching 0-d arrays and NumPy scalars

2008-02-22 Thread Francesc Altet
A Thursday 21 February 2008, Konrad Hinsen escrigué: > I agree. In fact, I'd rather see NumPy scalars move towards Python > scalars rather than towards NumPy arrays in behaviour. In particular, > their nasty habit of coercing everything they are combined with into > arrays is still my #1 source of

Re: [Numpy-discussion] Matching 0-d arrays and NumPy scalars

2008-02-22 Thread Francesc Altet
A Friday 22 February 2008, Stefan van der Walt escrigué: > Hi Travis, > > On Wed, Feb 20, 2008 at 10:14:07PM -0600, Travis E. Oliphant wrote: > > In writing some generic code, I've encountered situations where it > > would reduce code complexity to allow NumPy scalars to be "indexed" > > in the sam

Re: [Numpy-discussion] Matching 0-d arrays and NumPy scalars

2008-02-21 Thread Konrad Hinsen
On 21.02.2008, at 18:40, Alan G Isaac wrote: x = N.array([1,2],dtype='float') x0 = x[0] type(x0) > > > So a "float64 value" is whatever a numpy.float64 is, > and that is part of what is under discussion. numpy.float64 is a very recent invention. During the first decade of

Re: [Numpy-discussion] Matching 0-d arrays and NumPy scalars

2008-02-21 Thread Eric Firing
Travis E. Oliphant wrote: >> Travis, >> >> You have been getting mostly objections so far; > I wouldn't characterize it that way, but yes 2 people have pushed back a > bit, although one not directly speaking to the proposed behavior. > > The issue is that [] notation does more than just "select

Re: [Numpy-discussion] Matching 0-d arrays and NumPy scalars

2008-02-21 Thread Anne Archibald
On 21/02/2008, Stefan van der Walt <[EMAIL PROTECTED]> wrote: > Could I ask that we also consider implementing len() for 0-d arrays? > numpy.asarray returns those as-is, and I would like to be able to > handle them just as I do any other 1-dimensional array. I don't know > if a length of 1 wo

Re: [Numpy-discussion] Matching 0-d arrays and NumPy scalars

2008-02-21 Thread Stefan van der Walt
Hi Travis, On Wed, Feb 20, 2008 at 10:14:07PM -0600, Travis E. Oliphant wrote: > In writing some generic code, I've encountered situations where it would > reduce code complexity to allow NumPy scalars to be "indexed" in the > same number of limited ways, that 0-d arrays support. > > > For examp

Re: [Numpy-discussion] Matching 0-d arrays and NumPy scalars

2008-02-21 Thread Stefan van der Walt
On Thu, Feb 21, 2008 at 12:08:32PM -0500, Alan G Isaac wrote: > On Thu, 21 Feb 2008, Konrad Hinsen apparently wrote: > > > What I see as more fundamental is the behaviour of Python container > > objects (lists, sets, etc.). If you add an object to a container and > > then access it as an element

Re: [Numpy-discussion] Matching 0-d arrays and NumPy scalars

2008-02-21 Thread Charles R Harris
On Thu, Feb 21, 2008 at 12:30 PM, Travis E. Oliphant <[EMAIL PROTECTED]> wrote: > > > Travis, > > > > You have been getting mostly objections so far; > I wouldn't characterize it that way, but yes 2 people have pushed back a > bit, although one not directly speaking to the proposed behavior. > I

Re: [Numpy-discussion] Matching 0-d arrays and NumPy scalars

2008-02-21 Thread Travis E. Oliphant
> Travis, > > You have been getting mostly objections so far; I wouldn't characterize it that way, but yes 2 people have pushed back a bit, although one not directly speaking to the proposed behavior. The issue is that [] notation does more than just "select from a container" for NumPy arrays

Re: [Numpy-discussion] Matching 0-d arrays and NumPy scalars

2008-02-21 Thread Alan G Isaac
On Thu, 21 Feb 2008, Konrad Hinsen apparently wrote: > A float64 array is thus a container of float64 values. Well ... ok:: >>> x = N.array([1,2],dtype='float') >>> x0 = x[0] >>> type(x0) >>> So a "float64 value" is whatever a numpy.float64 is, and that is part of what is u

Re: [Numpy-discussion] Matching 0-d arrays and NumPy scalars

2008-02-21 Thread Eric Firing
Travis E. Oliphant wrote: > Hi everybody, > > In writing some generic code, I've encountered situations where it would > reduce code complexity to allow NumPy scalars to be "indexed" in the > same number of limited ways, that 0-d arrays support. > > For example, 0-d arrays can be indexed with >

Re: [Numpy-discussion] Matching 0-d arrays and NumPy scalars

2008-02-21 Thread Konrad Hinsen
On Feb 21, 2008, at 18:08, Alan G Isaac wrote: > I do not think anyone has really defended this behavior, > *but* the reply to me when I suggested that a matrix > contains arrays and we should see that in its behavior > was that, no, a matrix is a container of matrices so this is > what you get.

Re: [Numpy-discussion] Matching 0-d arrays and NumPy scalars

2008-02-21 Thread Alan G Isaac
On Thu, 21 Feb 2008, Konrad Hinsen apparently wrote: > What I see as more fundamental is the behaviour of Python container > objects (lists, sets, etc.). If you add an object to a container and > then access it as an element of the container, you get the original > object (or something that beh

Re: [Numpy-discussion] Matching 0-d arrays and NumPy scalars

2008-02-21 Thread Konrad Hinsen
On Feb 21, 2008, at 16:03, Travis E. Oliphant wrote: > However, I think my proposal for limited indexing capabilities > should be > considered separately from coercion behavior of NumPy scalars. NumPy > scalars are intentionally different from Python scalars, and I see > this > difference gro

Re: [Numpy-discussion] Matching 0-d arrays and NumPy scalars

2008-02-21 Thread Travis E. Oliphant
Damian Eads wrote: > While we are on the subject of indexing... I use xranges all over the > place because I tend to loop over big data sets. Thus I try avoid to > avoid allocating large chunks of memory unnecessarily with range. While > I try to be careful not to let xranges propagate to the nd

Re: [Numpy-discussion] Matching 0-d arrays and NumPy scalars

2008-02-21 Thread Damian Eads
While we are on the subject of indexing... I use xranges all over the place because I tend to loop over big data sets. Thus I try avoid to avoid allocating large chunks of memory unnecessarily with range. While I try to be careful not to let xranges propagate to the ndarray's [] operator, there

Re: [Numpy-discussion] Matching 0-d arrays and NumPy scalars

2008-02-21 Thread Travis E. Oliphant
Konrad Hinsen wrote: > On 21.02.2008, at 08:41, Francesc Altet wrote: > > >> Well, it seems like a non-intrusive modification, but I like the >> scalars >> to remain un-indexable, mainly because it would be useful to raise an >> error when you are trying to index them. In fact, I thought that

Re: [Numpy-discussion] Matching 0-d arrays and NumPy scalars

2008-02-21 Thread Damian Eads
In MATLAB, scalars are 1x1 arrays, and thus they can be indexed. There have been situations in my use of Numpy when I would have liked to index scalars to make my code more general. It's not a very pressing issue for me but it is an interesting issue. Whenever I index an array with a sequence o

Re: [Numpy-discussion] Matching 0-d arrays and NumPy scalars

2008-02-20 Thread dmitrey
Travis E. Oliphant wrote: > Hi everybody, > > In writing some generic code, I've encountered situations where it would > reduce code complexity to allow NumPy scalars to be "indexed" in the > same number of limited ways, that 0-d arrays support. > > For example, 0-d arrays can be indexed with > >

Re: [Numpy-discussion] Matching 0-d arrays and NumPy scalars

2008-02-20 Thread Konrad Hinsen
On 21.02.2008, at 08:41, Francesc Altet wrote: > Well, it seems like a non-intrusive modification, but I like the > scalars > to remain un-indexable, mainly because it would be useful to raise an > error when you are trying to index them. In fact, I thought that when > you want a kind of scalar

Re: [Numpy-discussion] Matching 0-d arrays and NumPy scalars

2008-02-20 Thread Francesc Altet
A Thursday 21 February 2008, Travis E. Oliphant escrigué: > Hi everybody, > > In writing some generic code, I've encountered situations where it > would reduce code complexity to allow NumPy scalars to be "indexed" > in the same number of limited ways, that 0-d arrays support. > > For example, 0-d