# [PYTHON MATRIX-SIG] RubberIndex

**Chris Chase S1A
**
chris.chase@jhuapl.edu

*Fri, 23 Feb 1996 19:06:19 -0500*

I made a suggestion about having array indexing generate an error when
too few indexes are used. Konrad felt that the analogy to lists was
more important:
>>>>>* "Konrad" == Konrad HINSEN <hinsenk@ere.umontreal.ca> writes:
*
Konrad> That wasn't my point either. My point is that since arrays and nested
Konrad> lists are treated as interchangeable in many situations, it makes
Konrad> sense to use this analogy as much as possible and allow an indexing
Konrad> scheme for arrays that matches that for nested arrays. WHich means
Konrad> that it should always be allowed to have just one index, independent
Konrad> of the rank of the array.
For an array 'a' (rank > 1), the current implementation of a[0] adds
no functionality since it is equivalent to a[0,...].
I would like to make another suggestion along the lines my original
one that also handles the purpose of ravel() for both assignment and
selection.
In IDL, Tela and Yorick using a single index or slice defaults to
indexing an array in flattened form. Otherwise, the number of actual
indexes used must equal the rank.
A similar implementation could be supported for the array object.
This obviates 'flat' attribute that I suggested earlier.
a[i] indexes 'a' in flattened form. 'i' can be a scalar or a slice. Then,
a[:] == ravel(a)
and assignment to 'a' in flattened form would also be supported:
a[i] = 2
which eliminates the need for a "flattened" assignment function or for
ravel().
Like other array languages, if more than one index is used without a
rubber index and there are fewer indexes than the array rank then an
error should result.
If 'a' has rank 3, then
a[0] = 1
b = a[0,...]
b = a[0,0,0]
would be valid. But a[0,0] would generate an error. This would be
consistent with the fact that a[0,0,0,0] also generates an error.
This implementation still allows an array to be used anywhere where a
sequence object (e.g. list) is used.
Chris
=================
MATRIX-SIG - SIG on Matrix Math for Python
send messages to: matrix-sig@python.org
administrivia to: matrix-sig-request@python.org
=================