[PYTHON MATRIX-SIG] RubberIndex
Chris Chase S1A
chris.chase@jhuapl.edu
Tue, 13 Feb 1996 12:14:21 -0500
>>>>> "Konrad" == Konrad HINSEN <hinsenk@ere.umontreal.ca> writes:
Konrad> '...' at the end of an index expression makes no sense, as you could
Konrad> just as well leave it out (a[0, ...] is the same as a[0]).
It makes perfect sense. Just because there is another way to
accomplish the same thing does not make it bad.
In fact, I would prefer to eliminate a[0] in preference of a[0,...].
I do not like the fact that an error is not generated if I use to few
indexes. For example, suppose 'a' has shape (2,4,5,6). I want the
first element but either I forget that it is rank 4 or incorrectly
enter the index:
scalar = a[0,0,0]
Instead of a scalar, I get an array with shape (6,). This "feature"
requires that I check the rank of every parameter passed into a
function for the desired rank. If I really want the last dimension as
a vector I could specify
vector = a[0,0,0,...]
vector = a[0,0,0,:]
I would prefer an error be produced by a[0,0,0]. An error already
occurs when specifying too many indexes, i.e. a[0,0,0,0,0]. The same
should occur for too few indexes unless a rubber index "..." is
present (although even with a rubber index too indexes is an error).
When using IDL, I have found that an error for too few indexes to be
very useful in quickly finding mistakes in code. Without this error,
I might not find out about the bug until much later in my code and
then I might have a difficult time tracing it back to its origin.
The only purpose I see for a[0] to be valid is to make it look like a
list for indexing so that a[0][1] is valid. I suppose that if we want
an array to be a specialized or subclassed list (so that it works
wherever a list occurs) then this has to be supported. But if we
think of an array as more of a dictionary than a list it should not
support this kind of indexing. I could see that it could lead to
confusion when we have multi-dimensional arrays of other types of
python objects. Suppse 'a' is a rank 2 array containing a
subscriptable python object. a[0,0][1] and a[0][0][1] would be valid.
However, if 'a' had a rank different than 2 then we could have it
produce an error - alerting the user that the object is not what he
thought.
Chris
=================
MATRIX-SIG - SIG on Matrix Math for Python
send messages to: matrix-sig@python.org
administrivia to: matrix-sig-request@python.org
=================