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

Alexander Belopolsky alexander.belopolsky at gmail.com
Mon Jan 9 12:37:05 CST 2006


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 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[()]?

-- sasha

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)).




More information about the Numpy-discussion mailing list