[MATRIX-SIG] reverse of take?

Konrad Hinsen hinsen@ibs.ibs.fr
Fri, 27 Jun 1997 11:18:29 +0200


> existing method, it's better to use that syntax. I think you can get this
> pretty easily with __setitem__  or __setslice__, so the syntax shouldn't
> really be an issue.

Indeed. A single subscript of any type is passed to __getitem__:

  x[[1, 3, 5]]  -->  x.__getitem__([1, 3, 5])

Several subscripts are passed as a tuple:

  x[[1, 3, 5], [3, 2, 5]] -->  x.__getitem__(([1, 3, 5], [3, 2, 5]))

Of course __setitem__ works in the same way. For C types it's a bit
more complicated since integers are passed via the sequence interface
whereas everything else gets passed via the mapping interface, but
it's not a real problem either.

So the difficult part is not syntax, but implementing the indexing
operations in a general and efficient way.
-- 
-------------------------------------------------------------------------------
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
_______________