[PYTHON MATRIX-SIG] take() in 1.0a2 (longish, sorry)

Carlos Fonseca fonseca@gaivota.demon.co.uk
Sun, 18 Aug 1996 16:21:07 +0100 (BST)


On Sun, 18 Aug 1996, Konrad Hinsen wrote:

>    I.e., when take is given a 2 dimensional indices array, it adds yet
>    another dimension to a. This should not happen if take(a,argsort(a,-1),-1) 
> 
> I hope that this intentional, since it is a very useful function
> for the construction of higher-rank arrays.

But the point is that higher-rank arrays can be easily and efficiently
constructed by adding dummy dimensions and relying on broadcasting,
whereas the reverse is not possible if functions insist on producing
higher-rank arrays. At least, it means that more memory must be allocated
before the higher-rank arrays can be indexed at all.

>    is to be equivalent to sort(a,-1). Note that, in the example above,
> 
> If sort(a,-1) is what you want, then that is what you should write.
> take() is meant for different (and much more diverse) applications,
> and I don't see a reason to limit its flexibility just to create
> a less efficient synonym for sort().

I have answered this in my previous message. Also, see above.

> My definition for take(), using the convenient J concepts of
> frames and cells, would be: the result has the frames of the
> index argument with elements picked from the value argument,
> i.e. if
>    b = take(a, i, axis)
> then
>    b[n_1,..,n_k] = a[(axis-1)*(All,), i[n_1,..,n_k], ...]
> with k being the rank of i.
> 
> Konrad.

This behaviour can be achieved efficiently with the definition I
proposed via broadcasting. The opposite behaviour can only be achived from
this one, if at all, via indexing. Meanwhile, lots of memory have already
had to be allocated.

Carlos



=================
MATRIX-SIG  - SIG on Matrix Math for Python

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