[Numpy-discussion] matrix indexing question

Joachim Dahl dahl.joachim@gmail....
Tue Mar 27 15:53:16 CDT 2007

```On 3/27/07, Zachary Pincus <zpincus@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://projects.scipy.org/pipermail/numpy-discussion/attachments/20070327/2d9fa05b/attachment-0001.html
```