[MATRIX-SIG] reverse of take?

Zane C. Motteler motteler@laura.llnl.gov
Tue, 1 Jul 1997 07:41:19 -0700 (PDT)


On Mon, 30 Jun 1997, Andrew P. Mullhaupt wrote:

>
>Can you index a multi-dimensional array with a one-dimensional array? In
>other words does arraytype[range(10)] refer to the first 10 elements of
>the array? I think this would be doable using other more verbose methods,
>but this is a simple way to spell this.
>
>Can you index a one-dimensional array with a multi-dimensional array? In
>languages which provide this, this usually returns a value with the same
>shape as the matrix and the values corresponding to the value in the vector
>with that index. This is really nice for image processing - for example
>palette remapping. You can get this by applying a function, but that is
>usually a lot slower.

Both cases are ambiguous in NumPy. NumPy arrays are not necessarily
stored contiguously (transpose merely exchanges some dimensions and
strides, but doesn't move any elements). This is obviously done for
speed. Secondly, to do these two things, even if arrays are contiguous,
means that users have to know whether arrays are stored in row-major or
column-major order, which is antithetical to the idea of a high-level
language.

>
>If array0 is d-dimensional and arrayk is 1-dimensional for  1<=k<=d, does
>array0[array1, ..., arrayd] refer to the elements corresponding to the
>Cartesian product of array1 ... arrayd? It should. What is the shape
>of the result when some of the index arrays have length 1? Should there be
>an additional argument to control this? (In S, x[1,1:5] is 1-dimensional with
>length 5 and x[1,1:5,drop=F] is 2-dimensional with shape (1, 5). - The reason
>you probably want this is that it can be really annoying to reshape the
>result which has been collapsed if it was an intermediate expression.)

Getting too esoteric here. I'm not even too sure how useful this would
be. It really demands intimate knowledge of the internal structure of
arrays.

>
>1. A function which returns the permutation which would put the elements of
>   a 1-d array in order. In APL this is called 'upgrade' and in S it is called
>   'order'. A quick illustration of the use of this is computing the ranks
>   of elements in a vector - I'll suppose we call the function order.
>
>    def rank(x) :
>            return order(order(x))

My arrayfnsmodule has such a function, called index_sort.

Zane

-----------------------------------------------------------------------------
Zane C. Motteler, Ph. D.                  ___________ALSO:_________________
Computer Scientist                        | Professor Emeritus of Computer|
Lawrence Livermore National Laboratory    |   Science and Engineering     |
P O Box 808, L-472                        | California Polytechnic State  |
Livermore, CA 94551-9900                  |   University, San Luis Obispo |
510/423-2143                              ---------------------------------
FAX 510/423-9969
zcm@llnl.gov or motteler@laura.llnl.gov or zmottel@calpoly.edu


_______________
MATRIX-SIG  - SIG on Matrix Math for Python

send messages to: matrix-sig@python.org
administrivia to: matrix-sig-request@python.org
_______________