[MATRIX-SIG] reverse of take?

Konrad Hinsen hinsen@ibs.ibs.fr
Tue, 1 Jul 1997 10:58:43 +0200


> I propose that arraytype[arraytype] automatically be interpreted
> as (1) gather as a value (2) scatter as an l-value.  I apologize if
> this is obviously dumb, incompatible with existing usage, or
> already proposed (I'm new, remember, don't hurt me!) :). 

Probably it has already been proposed, since anything imaginable has
already been proposed.  ;-)

Let's make this a bit more specific:

  array[sequence [, sequence [, sequence ...]]

would be the most general form, with any sequence of integers allowed.
But if we allow tuples, we have to decide on the interpretation of

  array[(2, 3)]

For compatibility this will have to remain equivalent to array[2, 3].
(In fact we have little choice there; this equivalence is enforced by
the interpreter.) So allowing tuples creates trouble. On the other
hand, not allowing tuples creates a very unpythonic restriction. So
there's the first problem to be resolved.

Second problem: do we allow arrays of rank > 1 as indices? If yes,
what are the exact semantics? One interpretation would make

  a[b]

an array of the same shape as b with a[b][i, j, k,...] = a[b[i, j, k,...]].
This gets a bit complicated when a has rank > 1, but it's still doable
and probably useful.

Third problem: an index sequence can contain the same index more than
once. Fine for extracting data from an array, but what is supposed
to happen if this occurs on the left-hand side? For example, what is

  a[[0, 1, 0]] = [1, 2, 3]

supposed to do?
-- 
-------------------------------------------------------------------------------
Konrad Hinsen                          | E-Mail: hinsen@ibs.ibs.fr
Laboratoire de Dynamique Moleculaire   | Tel.: +33-4.76.88.99.28
Institut de Biologie Structurale       | Fax:  +33-4.76.88.54.94
41, av. des Martyrs                    | Deutsch/Esperanto/English/
38027 Grenoble Cedex 1, France         | Nederlands/Francais
-------------------------------------------------------------------------------

_______________
MATRIX-SIG  - SIG on Matrix Math for Python

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