[Numpy-discussion] Status of numeric3 / scipylite / scipy_core

Travis Oliphant oliphant at ee.byu.edu
Thu Mar 17 14:03:32 CST 2005

```Perry Greenfield wrote:

> Before I delve too deeply into what you are suggesting (or asking),
> has the idea to have a slice be equivalent to an index array been
> changed. For example, I recall seeing (I forget where), the suggestion
> that
>
> X[:,ind] is the same as X[arange(X.shape[0]), ind]
>
This was in the PEP originally.  But, after talking with you and better
understanding the "broadcasting" issues of the numarray indexing scheme,
it seemed less like a good idea.  Then, during implementation it was
easier to interpret slices differently.  A very natural usage fell out
as I thought more about  partial indexing in Numeric:  X[ind] where X
has more than 1 dimension returns in numarray something like

result[i,j,k,...] = X[ind[i,j,k],...]

It seems rather singular to have this Ellipsis-like character only
useful for the ending dimensions of X.  Thus, I decided that X[...,ind]
ought to be valid as well and return something like

result[...,i,j,k] = X[...,ind[i,j,k]]

and realized a better solution).

> The following seems to be at odds with this. The confusion of mixing
> slices with index arrays led me to just not deal with them in
> numarray. I thought index arrays were getting complicated enough. I
> suppose it may be useful, but I would be good to give some motivating,
> realistic examples of why they are useful. For example, I can think of
> lots of motivating examples for:
>
> using more than one index array (e.g., X[ind1, ind2])
> allowing index arrays to have arbitrary shape
> allowing partial indexing with index arrays

Give me the reason for allowing partial indexing with index arrays, and
I bet I can come up with a reason why you should allow X[...,ind] as
well (because there is an implied ... at the end when you are using
partial indexing anyway).

>
> Though I'm not sure I can think of good examples of arbitrary
> combinations of these capabilities (though the machinery allows it).
> So one question is there a good motivating example for
> X[:, ind]? By the interpretation I remember (maybe wrongly), I'm not
> sure I know where that would be commonly used (it would suggest that
> all the sizes of the sliced dimensions must have consistent lengths
> which doesn't seem typical. Any one have good examples?

So, I've scaled back my "intermingling" of index arrays with other types
of arrays (you'll also notice in the current PEP that I've gotten rid of
mixing boolean and index arrays).

I think the usage I define in the PEP for mixing slices, Ellipses, and
index arrays is reasonable (and not difficult to implement) (it's
bascially done --- minus bug fixes).

-Travis

```