[Numpy-discussion] matrix indexing question

Joachim Dahl dahl.joachim at gmail.com
Tue Mar 27 16:53:16 EDT 2007


On 3/27/07, Zachary Pincus <zpincus at stanford.edu> wrote:
>
>
> So we are left with the current behavior:
> (a) M[i,:] is a matrix.
> (b) M[i] is a matrix.
> (c) Iteration over M yields matrices.
>
>
I find it useful if M[i] indexes the matrix interpreted as a column-vector
(vec(M), or M(:) in
Matlab notation),  e.g.,  you could pick out the diagonal as M[::n+1],  or
if N is an index-set
of certain elements in M,  then you could access those elements as M[N].
Then I would also say that iterating over a matrix should just return the
elements of vec(M) one by
one.

In general, I think the Matlab notation works well:
* M[I,J]  where I and J and index-sets returns a len(I) x len(J) matrix
* M[I] returns a len(I) vector (a column or row vector depending on
orientation of I)
The index-sets could be a single integer, a list, or a slice.

But I can see there are good arguments for using the NumPy conventions as
well...
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20070327/2d9fa05b/attachment.html>


More information about the NumPy-Discussion mailing list