[PYTHON MATRIX-SIG] Functions and names

Chris Chase S1A chris.chase@jhuapl.edu
Fri, 23 Feb 1996 17:34:13 -0500


I apologize that this response is delayed.  My regular work takes
priority over my attention to the SIG mailing list.

>>>>> "Konrad" == Konrad HINSEN <hinsenk@ere.umontreal.ca> writes:

Chase>    Support for mapped indexing (like the Tela language) would
Chase>    be useful.  Perhaps it should be an attribute so as to
Chase>    allow assignment:

Konrad> Could you give an example for an application where this would
Konrad> be useful?

One application where I use this:

I often use map projections (e.g. azimuthal) to represent regularly
sampled data on a sphere (latitude/longitude or azimuth/elevation
coordinates), i.e. data is a 2D array on a regularly sampled lat/lon
grid.  One way to map data onto the map projection is to compute the
lat/lon coordinate of each pixel in the map.  Suppose the map is to be
an NxM image for a particular projection and that the NxM arrays 'lat'
and 'lon' contain the latitude and longitude coordinates of each pixel
in map.  'lat' and 'lon' then are converted to indexes according to the
grid sampling.

Then mapped indexing produces the desired map image:

map = data.mapped(lat,lon)

As I mentioned previously, I use this kind of indexing when dealing
with coordinates for 2D image maps or 3D volume data.  The coordinates
are often used as part of a transformation (as above) or a path
through the data (i.e. a line-of-sight).

For more info, mapped indexing is supported in both IDL and Tela.
See http://www.geo.fmi.fi/prog/tela/telahelp-5.html#ss5.18.

Chase>    There needs to be a dual capability for assigning the items
Chase>    specified by an array of indices (a completely general form
Chase>    of product indexing).

Konrad> I agree that this would be nice, but if I remember correctly
Konrad> there was some problem with putting this into indexing.

Originally, James Hugunin had implemented general index vectors.
However, he stated that they were removed when he decided to have
array indexing return by reference.  Index vectors do not fit well
into this implementation.  Returning by reference would require
keeping a copy of the index vector and would require a rewrite of the
current array representation.  Besides, I think it is more natural to
return a copy of the indexed elements rather than a reference when
using a general index vector.

When the operation is assignment there is no reason to not support
index vectors since array references are not being created.

Just because general product indexing does not completely fit into
the current implementation is not a good reason to not support it.
Rather than mess around with the current indexing that returns by
reference, I suggested a 'subarray' attribute that would support
general product indexing for assignment and selection (returning a
copy).

Chase>    An insertion method for inserting a subarray into a larger
Chase>    array would also be useful.  Something like:

Konrad> The APL way of doing this is to use what I call repeat() to make
Konrad> room for the insertion and then assign to this part. Since this
Konrad> is not a very frequent operation, I don't think we need a special
Konrad> function for it.

I specifically said that the function I was describing overwrites
elements in the target array rather than making room.  True it is not
as frequent of an operation as some others, but it is one that I use
other with matrix linear algebra (manipulating block matrices) and for
cut-away's and slices in 3D volume data.  It is a general operation
supported by other languages and not application specific.

Konrad> 2.1.3) Combining a group of axes into one axis (see comment 2):
Konrad> +      a[i1, i2, ......, i3, i4]  (see comment 3)
Konrad> The double ellipsis works similar to the single one, but
Konrad> contracts all the axes covered into a single axis.

Chase>    I do not like this.  Perhaps an attribute 'collapse' would
Chase>    work?  E.g.

Chase>    a.collapse[i1, i2, ..., i3, i4]

Konrad> If that can be done, fine. So what should the value of "collapse" be
Konrad> before subscripting? I can't see a way to make this work.

It would have to be an object containing a reference to the array 'a'.
It would have the special property that the ellipses index, '...',
collapses missing dimensions.  Otherwise it would act like a normal
array.  Since this is a special kind of access to the array object, a
'collapse' method would be better, but then it could not support the
indexing syntax for slices and ellipses.  I personally think that the
best solution would be a syntactical symbol like "*", but that idea
was shot down.


Chris

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

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