[Numpy-discussion] Call for a vote on .M .A .T .H attributes

Ed Schofield schofield at ftw.at
Fri Jul 7 04:06:00 CDT 2006

On 07/07/2006, at 6:26 AM, Travis Oliphant wrote:

> 1) .T  Have some kind of .T attribute


The meaning of .T is unclear for ndim != 2, as the plethora of sub- 
vote options shows. And we already have a matrix object designed  
explicitly for the case ndim == 2. Let's make matrix objects more  
useful, rather than give up on matrices and hard-wire 2d concepts  
into arrays. I'm willing to help with this, and I'll post some ideas  
to a different thread.

>    If >0 on this then:
>    a) .T == .swapaxes(-2,-1)
>    b) .T == .transpose()
>    c) .T raises error for ndim > 2
>    d) .T returns (N,1) array for length (N,) array
>    e) .T returns self for ndim < 2

(Just for the record, I think option (d) is positively evil.)

> 2) .H  returns .T.conj()


I'm against this for the same reasons I'm against .T, but more  
strongly, due to the extra memory allocation.

> 3) .M  returns matrix version of array


This would have the advantage of making .T and .H redundant for 2-d  
arrays, since they'd be accessible as matrix attributes anyway. But I  
don't see a strong enough case for this as an extra attribute, since  
asmatrix() and mat() are available anyway.

I would like to deprecate mat() as an alias for matrix (by moving mat  
to the oldnumeric namespace); this would break the expectation that  
mat() perform a copy, and allow users to write

 >>> from numpy import asmatrix as mat

instead if they need a short, simple syntax that avoids the copy  

It's also trivial for any serious user of matrices to write wrapper  
functions for ones, zeros, etc., such as

def matones(*args):
     return asmatrix(ones(*args))

There might be an argument for including these in e.g. the  
numpy.matrix namespace. This would make a .M attribute even less  

> 4) .A  returns basearray (useful for sub-classes).


This could be a good idea, but I'm not clear enough on its  
implications to vote either way.

-- Ed

More information about the Numpy-discussion mailing list