[PYTHON MATRIX-SIG] [munro@icf.llnl.gov: Re: Python Matrix extension tutorial]

Hinsen Konrad hinsenk@ere.umontreal.ca
Fri, 10 Nov 1995 16:36:20 -0500


   Yorick has one other indexing syntax which has proven useful, which I
   call "rubber indices".  They address the problem of writing
   interpreted code which extracts slices of arrays when you don't know
   beforehand how many dimensions the array has.  An example is an
   opacity array for which you know that the most slowly varying index
   represents photon wavelength, but there might be zero, one, two, or
   three faster varying dimensions representing position in space.  These
   situations can probably be handled with Python's reshape operator, so
   again this is a question of ease of use.

Maybe it helps to point out how this is handled in J and in my Array
module. There indexing is not seen as something special, but just as
one of many structural functions. Consequently it has no special
syntax (in my array module I have added bracket indexing as a kind of
syntactic sugar for the function take()), but is an ordinary function
with two arguments: the array to be indexed from, and an index array.

Accessing the first (or second etc.) dimension of an array of
arbitrary rank is then done by specifying a negative rank for the
indexing function. Negative function ranks basically mean that you do
not specify the rank of the cells that the function operates on, but
the rank of the frames of these cells. Maybe something similar could
be implemented in Python, although I don't see with what kind of
syntax one could indicate negative ranks for bracket indexing.

Personally, I'd like to see an additional indexing function similar in
spirit to the J version. I realise it can't replace bracket indexing,
since you can't assign to parts of a matrix this way, but it would be
a useful addition for many cases.

-------------------------------------------------------------------------------
Konrad Hinsen                     | E-Mail: hinsenk@ere.umontreal.ca
Departement de chimie             | Tel.: +1-514-343-6111 ext. 3953
Universite de Montreal            | Fax:  +1-514-343-7586
C.P. 6128, succ. Centre-Ville     | Deutsch/Esperanto/English/Nederlands/
Montreal (QC) H3C 3J7             | Francais (phase experimentale)
-------------------------------------------------------------------------------

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

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