[Numpy-discussion] What's wrong with matrices?

JJ josh8912 at yahoo.com
Sun Jul 9 03:10:27 CDT 2006


Ed Schofield <schofield <at> ftw.at> writes:

> 
> 
> On 08/07/2006, at 10:22 PM, JJ wrote:
> 
> > 3)  In some operations, especially range selection operations, a N, 
> > 1 matrix is
> > turned into a 1,N matrix.  This is confusing relative to matlab and  
> > problematic,
> > in my view.
> 
> This sounds like a bug.  Can you give any examples of this happening  
> with the latest release or SVN version?
> 
> > <snip>
> >
> > 5)  If X is a 1,n matrix, then X.T should return a n,1 matrix, I  
> > think.
> 
> This should be the case.  Could you post a code snippet that violates  
> it?
> 
> Thanks for your feedback, JJ!
> 
-----------------------------------------
Hello Ed:
Here are a couple of examples off the top of my head:

a = mat(arange(10))
a.shape = (5,2)
b = a.copy()
c = hstack((a,b))  # should return a matrix
type(c)
<type 'numpy.ndarray'>

a[where(a[:,0]<6)[0],0]  #should return a column
matrix([[0, 2, 4]])

My version is about a month old, so maybe these are fixed.  Since we are on the
topic, I dont understand why where() returns a tupple. To me, it just means
adding an extra '[0]' in many places in my code.  I would vote for where()
retuning a matrix (if matrix is the default in the session).  My comment on
transpose of a 1,n matrix producing a n,1 matrix was in response to a vote
question on the list.  Also, I would vote for X.A*Y.A to return a matrix, if
matrix is the default for a session.  Lastly, this might not be the right place
for this comment, but it would be nice if pylab allowed numpy matrices.  Then
code like:
plot(d.A.ravel().tolist())
could be changed to plot(d) 
Hope this is of some help.
JJ






More information about the Numpy-discussion mailing list