[PYTHON MATRIX-SIG] Slice expressions

Konrad Hinsen hinsen@ibs.ibs.fr
Wed, 16 Oct 96 17:52:33 +0100


> An ignorant question: does this give the functionality of
> a Fortran90 array mask (or logical indexes in Splus)?

Probably not, although I am not sure what you are talking about ;-)

> i.e. is there a NumPy equivalent to this Splus expression, which finds
> the warm, dark, sea-surface in a cloudy satellite image for which I
> have temperature and reflectivity:
> 
> seaSurfaceIndex -> (temp > 280) & (reflec < 0.10)
> meanSST -> mean(temp[seaSurfaceIndex])

No, that's something else, which you would do using repeat()
in NumPy:

  repeat(temp, logical_and(greater(temp, 280), less(reflec, 0.10)))

would give you all elements of temp corresponding to the selected
condition.


My code for index_expression lets you build up multidimensional index
expressions from pieces. You need this to index arrays whose
dimensionality is unknown when you write the code. An example: I have
written a class that represents a function given numerically on a grid
(with operations such as interpolation, integration, differentiation,
and polynomial fitting), which works for functions of any number of
variables. It must sometimes index along a particular axis given
as a number, i.e.

   a[::,::,::, ... ,::, 0]
     ---n times :: ---

Piecing together index expressions is no problem, as they are just
tuples, but *making* them requires a trick, because notations like ::
are syntactically legal only inside brackets. My index_expression code
just allows you to extract the tuple generated by indexing instead
of applying it directly.
-- 
-------------------------------------------------------------------------------
Konrad Hinsen                          | E-Mail: hinsen@ibs.ibs.fr
Laboratoire de Dynamique Moleculaire   | Tel.: +33-76.88.99.28
Institut de Biologie Structurale       | Fax:  +33-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
=================