[Numpy-discussion] matrix indexing question

Sebastian Haase haase@msg.ucsf....
Mon Mar 26 10:27:16 CDT 2007

On 3/26/07, Alan G Isaac <aisaac@american.edu> wrote:
> > Alan G Isaac schrieb:
> >> What feels wrong: iterating over a container does not give
> >> access to the contained objects.  This is not Pythonic.
> On Mon, 26 Mar 2007, Sven Schreiber apparently wrote:
> > If you iterate over the rows of the matrix, it feels
> > natural to me to get the row vectors
> Natural in what way?
> Again, I am raising the question of what
> would be expected from someone familiar with Python.
> Abstractly, what do you expect to get when you iterate
> over a container?  Seriously.
> > But I admit I'm a 2d fan so much so that I didn't even
> > know that using a single index is possible with a matrix.
> Exactly.  When you want submatrices, you expect to index for
> them.  EXACTLY!!
If may chime in...
I think Sven's argument in on the side saying,
A "matrix" is an object that you expect a certain (mathematical !)
behavior from.
If some object behaves intuitively right -- that's ultimately pythonic !
The clash is, NOT to see a matrix  "just as another container".
Instead a matrix is a mathematical object , that has rows and columns.
It is used in a field (lin-alg) where every vector is either a row or
a column vector -- apparently that's big thing ;-)
The whole reason to add a special matrix class to numpy in the first
place, is to provide a better degree of convenience to lin-alg related
applications.  I would argue that it was just not consistently
considered, that this should also come with "a column of a matrix is
something else than a row  -- (1,n) vs. (n,1)  and not (n,)

more notes/points:
a) I have never heard about the m.A1 - what is it ?
b) I don't think that if m[1] would return a (rank 2) matrix, that
m[1].A could return a (rank 1) array ...
c) I'm curious if there is a unique way to extend the matrix class
into 3D or ND.


More information about the Numpy-discussion mailing list