[Numpy-discussion] matrix wart

Stefan van der Walt stefan@sun.ac...
Fri Feb 22 02:37:07 CST 2008


On Thu, Feb 21, 2008 at 07:10:24PM -0500, Alan G Isaac wrote:
> > On Thu, Feb 21, 2008 at 12:08:32PM -0500, Alan G Isaac wrote:
> >> a matrix behavior that I find bothersome and unnatural::
> 
> >>     >>> M = N.mat('1 2;3 4')
> >>     >>> M[0]
> >>     matrix([[1, 2]])
> >>     >>> M[0][0]
> >>     matrix([[1, 2]])
> 
> 
> On Fri, 22 Feb 2008, Stefan van der Walt apparently wrote:
> > This is exactly what I would expect for matrices: M[0] is 
> > the first row of the matrix.
> 
> Define what "first row" means!
> There is no standard definition that says this is means the
> **submatrix** that can be created from the first row.
> Someone once pointed out on this list that one might 
> consider a matrix to be a container of 1d vectors.  For NumPy, 
> however, it is natural that it be a container of 1d arrays.
> (See the discussion for the distinction.)

Could you explain to me how you'd like this to be fixed?  If the
matrix becomes a container of 1-d arrays, then you can no longer
expect

x[:,0]

to return a column vector -- which was one of the reasons the matrix
class was created.  While not entirely consistent, one workaround
would be to detect when a matrix is a "vector", and then do 1-d-like
indexing on it.

> You "expect" this matrix behavior only from experience with it,
> which is why I "expect" it too, while hating it.

No, really, I don't ever use the matrix class :) But it is not like
the behaviour is set in stone, so I would spend less time hating and
more time patching.

> The example really speaks for itself. Since Konrad is an extremely
> experienced user/developer, his reaction should speak volumes.

Of course, I meant no disrespect to Konrad.  I'm just trying to
understand the best way to address your concern.

Regards
Stefan


More information about the Numpy-discussion mailing list