[MATRIX-SIG] reverse of take?

Konrad Hinsen hinsen@ibs.ibs.fr
Tue, 1 Jul 1997 17:15:46 +0200


> I think this does expose a flaw in the way in which multiple indexing
> is handled in python. That we cannot distinguish a[(2,3)] from a[2,3]

Right, but there wasn't much choice. To keep the existing interface
to both classes and C types, an index had to be limited to a single
Python object. And using tuples for multiple indexing is also useful
for code that has to build an index expression from pieces.

> is unfortunate. However, the potential ambiguity only arises if we
> allow rank 1 arrays to be indices for arrays of higher rank. If we

That is already allowed and well defined! However, it's not what
you seem to think it is. The definition is that the index is applied
to the first dimension of the array. This makes arrays (of any dimension)
conform to the sequence protocol, and makes them very interchangeable
with nested lists.

> In fact, we might be able to go yet further to, for example,
> a[:,b]. This would have shape the concatentaion of a.shape[0],
> b.shape[:-1] and a.shape[1+b.shape[-1]:] and a[:,b][i,j,k] would be
> the same as a[i][b[j,k]]

And be the first step to the perlization (or J-ization) of NumPy:
combinations of funny symbols having a meaning not deducible from
the meanings of their pieces. Besides, Guido will probably refuse
any syntax change of that kind!

> In S-Plus, a[0] becomes 3. In other words, some form of left to right
> evaluation should be used? We would have to be very careful to avoid
> ambiguity.

Especially for higher-dimensional cases!

> New problem:  Can we allow an expression such as
> 
> a[b][c] = d

Syntactically yes.

> S-Plus. Anyone got any suggestions as to how we should organise
> things? 

First we have to agree on what we want, and that could be difficult...
Then do an implementation in a separate module, with function syntax,
just for testing. In parallel, check with Jim (are you following all
this?) about the status of the NumPy source code - no point in
modifying code that is still changing. Finally, put it all together
and be happy...
-- 
-------------------------------------------------------------------------------
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
_______________