# [Numpy-discussion] matrix indexing question

Colin J. Williams cjw@sympatico...
Mon Mar 26 07:10:35 CDT 2007

```Alan G Isaac wrote:
>> Alan G Isaac wrote:
>>> So this ::
>>>     >>> x[1]
>>>     matrix([[1, 0]])
>>> feels wrong.  (Similarly when iterating across rows.)
>>> Of course I realize that I can just ::
>>>     >>> x.A[1]
>>>     array([1, 0])
>
>
> On Sun, 25 Mar 2007, "Colin J. Williams" apparently wrote:
>> An array and a matrix are different animals.  Conversion
>> from one to the other should be spelled out.
>
>
> But you are just begging the question here.
> The question is: when I iterate across matrix rows,
> why am I iterating across matrices and not arrays.
> This seems quite out of whack with general Python practice.
>
> You cannot just say "conversion should be explicit"
> because that assumes (incorrectly actually) that
> the rows are matrices.  The "conversion should be explicit"
> argument actually cuts in the opposite direction of what
> you appear to believe.

Alan,

Yes, this is where we appear to differ.  I believe that vectors are best
represented as matrices, with a shape of (1, n) or (m, 1).  The choice
of these determines whether we have a column or a row vectors.

Thus any (m, n) matrix can be considered as either a collection of
column vectors or a collection of row vectors.

If the end result is required as an array or a list, this can be done
explicitly with X[1].A or A[1].tolist().

Here, A is a property of the M (matrix) class.
>
> Cheers,
> Alan Isaac

A long time ago, you proposed that PyMatrix should provide for matrix
division in two way, as is done in MatLab.  This was implemented, but
PyMatrix has not yet been ported to numpy - perhaps this summer.

Regards,

Colin W.

```