[PYTHON MATRIX-SIG] Final conventions for alpha2

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

On Sun, 18 Aug 1996, Konrad Hinsen wrote:

> Obviously, but how often does this occur? (Of course I am not
> asking how often such code gets executed, but how often you have to
> type such a function call.) In all of my array code, which is not
> just Python code but also a few MB of APL code, such applications
> are extremely rare. Even if such an operation is central to GA
> applications, that doesn't mean that the majority of array functions
> in a complete program (i.e. including setup or reading of input
> arrays, analysis, output formatting, etc.) would benefit from a
> default axis of -1.

In wanting to write generic GA code, where the structures that
characterize the individual typically have known dimensions (fitness is a
scalar, performance is at most a vector (in multiobjective optimization),
but the structure of the population is a decision of who actually puts the
GA together, the code must be written relative the last dimension of the
array. Thus, -1 are -2 the axes that end up making sense.
If the population was assumed to be unstructured, then one of these would
equivalent to 0, but not in general.

> But of course you can convince me that I am wrong by sending me a few
> complete programs that do something useful and that need an axis
> specification of -1 in the majority of axis-related operations.

Not having a working take() (see one of my earlier messages) hasn't helped

> [explation of structural vs. non-structural]
> Of course that means that take(a,argsort(a)) doesn't do anything
> useful. But in what situation would you use it anyway? To sort the 1D
> subarrays of a, you would write sort(a) (which being non-structural
> should have a default axis of -1). 

But suppose I have to arrays, a and b, both aligned and three dimensional,
and that there is a ono to one correspondence between the elements of a
and those of b. I need to sort a and, at the same time, rearrange b so
that the original relationship is retained:


This should be enough.

> Using take() makes sense e.g. if
> you only want a subset of the elements, but I can't believe that this
> is a frequent operation.

This is called "selection" (one of the 3 main operators) operators.

> Besides, my APL experience tells me that
> argsort() is never used on anything but a rank-1 array.
> Konrad.

My experience is different. But Matlab doesn't let me write something
like the above even for 2d arrays, so I end up using a for-loop. 

Something else:

How can I achieve

rank = argsort(argsort(cost))

without having to call argsort twice? Something like an inverted take
(ekat below :-)

rank = ekat(arange(n),argsort(cost))

would be ideal. This would be like take, but "indices" would refer to the
output matrix, and not to the input.


MATRIX-SIG  - SIG on Matrix Math for Python

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