[PYTHON MATRIX-SIG] A problem with slicing

Hinsen Konrad hinsenk@ere.umontreal.ca
Thu, 14 Sep 1995 18:46:58 -0400

   I've been playing with another technique for indexing a matrix, borrowed  
   from matlab.  I've implemented indexing matrices with a matrix of booleans  
   (integers) that is the same size as the matrix being indexed (this only  
   makes sense for a setvalue).  This is trivially done using the mapping  
   semantics, and combined with some matrix comparision operators I've found  
   this quite useful.

Indeed. But how does it work for higher-dimensional arrays?

APL provides a similar functionality using an operator called
"compress".  Its boolean argument is always one-dimensional and it a
works along a specified axis. If used on the right-hand side of an
expression, it is simply filter(). In APL2 it may also be used on
the left hand side of an assignment, as btw can all expressions
that evaluate to a subset of elements of an array. This is an
extremely powerful feature, but so complicated to implement that
to my knowledge only IBM's mainframe version does it without

In summary, I like your proposal, adding that it ought to
work along one (arbitrary) axis for higher-dimensional arrays.

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. A                | 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