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

Perry Greenfield perry at stsci.edu
Fri Mar 18 10:58:14 EST 2005

On Mar 18, 2005, at 10:08 AM, Paul Barrett wrote:

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

A common task is to obtain a list of values from an image based on a 
list (array) of i,j locations in the image. These index arrays may have 
come from some other source (say a catalog of known star positions) or 
from a function that obtained the positions of local maxima found in a 
corresponding (but different image) for the purposes of comparing the 
image objects with another image's objects.

>> allowing index arrays to have arbitrary shape

A classic example is using the array to be indexed as a lookup table. 
If I have byte image and wish to transform it to a different greyscale 
using a lookup table, I can use the byte image as a index array for the 
lookup table array.

transformedimage = lookuptable[image]

>> allowing partial indexing with index arrays

Here I'll go one better, a combination of the previous and this one 
using a similar mechanism, except to generate rgb values. The lookup 
table now is a 256x3 array representing how each of the 256 possible 
byte values are to be mapped to an rgb value

rgbimage = lookuptable[image]

Here the rgbimage has shape (image.shape[0],image.shape[1],3)

But partial indexing can be used for other things such as selecting 
from a set of weighting functions or images to be used against a stack 
of 1-d arrays or images respectively for subsequent processing (e.g., 

> Can you give a few then?  Say one or two for each of the three 
> scenarios.

Others may be able to come with better or alternative examples.

More information about the NumPy-Discussion mailing list