[PYTHON MATRIX-SIG] Functions and names
Konrad HINSEN
hinsenk@ere.umontreal.ca
Tue, 20 Feb 1996 17:38:41 -0500
I must admit that for constructing matrices the nested list argument
seemed natural. This version does not allow it. Otherwise, I like
its additional functionality.
Of course this is still allowed! That was what I meant with the
somewhat cryptic comment that the shape is inferred from the sequence
if not explicitly specified.
Support for mapped indexing (like the Tela language) would be useful.
Perhaps it should be an attribute so as to allow assignment:
Could you give an example for an application where this would
be useful?
Konrad> 1.2) Selecting arbitrary elements specified by an array of indices i:
Konrad> + take(a, i, axis=0)
Konrad> Conditions: i must be of an integer array type,
Konrad> minimum.reduce(ravel(i)) >= 0,
Konrad> maximum.reduce(ravel(i)) < a.shape[axis]
As Paul suggested, perhaps gather() is a better name than take()
(gather is a name used in vector libraries). But it really does not
matter very much to me.
I explicitly avoided "gather" for two reasons:
1) It is not a particularly clear description of what is happening.
2) What I describe is not the exact equivalent of what you
find in most vector libraries, because the index array can
have a higher rank than 1.
There needs to be a dual capability for assigning the items specified by
an array of indices (a completely general form of product indexing).
I agree that this would be nice, but if I remember correctly there
was some problem with putting this into indexing.
An insertion method for inserting a subarray into a larger array would
also be useful. Something like:
The APL way of doing this is to use what I call repeat() to make
room for the insertion and then assign to this part. Since this
is not a very frequent operation, I don't think we need a special
function for it.
flatten() could also be a possible name. Why should this be a
function rather than a method or attribute? For example,
a.flat == ravel(a)
As I pointed out in an earlier message, we should better avoid methods
for array operations except for very specialized ones (like byteswap
or typecode). There is simply no clean way to decide what should be
a method and what a function, and besides all operations coded in
Python have to be functions anyway. (This, by the way, is the
current distinction: everything implemented in C is a method, everything
else is a function. I think we agree that this is the worst possible
distinction.)
but a.flat[s] would allow subscription/assignment of 'a' in flattened
form using a scalar, sequence object, or a slice. Of course a
So will a function, if it doesn't copy the array but returns a
reference.
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.
I do not like this. Perhaps an attribute 'collapse' would work? E.g.
a.collapse[i1, i2, ..., i3, i4]
If that can be done, fine. So what should the value of "collapse" be
before subscripting? I can't see a way to make this work.
Konrad> 2.1.4) Adding an axis of length 1:
Konrad> a[..., NewAxis, ...]
Of course the "..." are notational and have nothing to do with ellipses
indexes. Otherwise, this does not make sense.
Of course. I hadn't thought about this possible confusion.
Yorick has a nice general form of the transpose() function. It allows
a variable length argument list where the arguments are cyclic
permutations of the indexes. It is actually a little more general.
I think this is close to what I wanted to describe. I'll have
to look up the Yorick documentation...
-------------------------------------------------------------------------------
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
=================