[SciPy-dev] [Numpy-discussion] Re: How to handle a[...] in numpy?

Francesc Altet faltet at carabos.com
Tue Jan 10 00:02:00 EST 2006


A Dilluns 09 Gener 2006 21:36, Alexander Belopolsky va escriure:
> On 1/9/06, Francesc Altet <faltet at carabos.com> wrote:
> > However, the original aim of the "..." (ellipsis) operator is [taken
> > for the numarray manual]:
> >
> > """
> > One final way of slicing arrays is with the keyword `...' This keyword
> > is somewhat complicated. It stands for "however many `:' I need
>
> This is precisely my motivation for making a[...] the same as a[()] for
> zero rank a.  In this case "however many" is zero. In other words, a[...]
> is a short-hand
> for a[(slice(None),)*len(a.shape)]. Specifically, if a.shape = (),
> then a[...] = a[()].

I see your point. I was just proposing a way to return different
objects for [...] and [()] that were consistent with higher
dimensionality. So if one has a non-0 dimensional array (tensor)
called a, then a[...] will return exactly the same object, so the same
should be done with 0-d arrays (tensors) IMO. Now, the () index in 0d
objects is just a way to substitute integer indexes in higher
dimensional objects, and should return a scalar type, as it does
in the later case.

I recognize that this is my interpretation of the facts and chances
are that I'm completely wrong with this. Anyway, sometimes I tend to
think that this kind of issues are not very important, but from time
to time they will certainly bit us, so perhaps this discussion would
be useful for the community in the future.

> > I don't know for old versions of Numeric, but my impression is that
> > the ellipsis meaning is clearly stated above. In fact, in a
> > 4-dimensional array, say a, a[...] should be equivalent to a[:,:,:,:]
> > and this does not necessarily implies a copy.
>
> I am not proposing any change for rank > 0 arrays, nor for the new numpy
> scalars.  For a = array(0), why would you want a[...] have different
> type from a[()]?
> If as for rank-4 array a, a[...] should be equivalent to a[:,:,:,:]
> why would you expect
> a[...] for a rank-0 a be different from a[()]?

For the reasons mentioned above: just to be consistent with higher
dimensions (although as it turns out to be, the interpretation of
"consistency" is different between both of us) and to have two
different objects returned from [...] and [()].

> PS: There seems to be a terminological difficulty discussing this type
> of things. You call an array that takes 4 indices a 4-dimensional
> array, but in algebra 4-dimensional vector is a sequence of 4 numbers
> (array of shape (4,)).  An object that is indexed by 4 numbers is a
> tensor of rank 4 (array of shape (n1, n2, n3, n4)).

That's true. However, in the Numeric/numarray/numpy literature I think
N-dimensional arrays are generally understood as tensors of rank-N.
From the scipy manual ("Object Essentials" chapter):

""" NumPy provides two fundamental objects: an N-dimensional array
object (ndarray) and... """

But anyway, I think that, provided the context is clearly defined, the
probability of being misled is (hopefully) quite low.

Regards,

-- 
>0,0<   Francesc Altet     http://www.carabos.com/
V   V   Cárabos Coop. V.   Enjoy Data
 "-"





More information about the NumPy-Discussion mailing list