[Numpy-discussion] adding a .M attribute to the array.

Travis Oliphant oliphant.travis at ieee.org
Tue Mar 5 20:36:02 EST 2002


Recently there has been discussion on the list about the awkwardness of 
matrix syntax when using Numeric Python.

Matrix expressions can be awkard to express in Numeric which is a negative 
mark on an otherwise excellent computing environment.

Currently part of the problem can be solved by working with Matrix objects 
explicitly:

a = Matrix.Matrix("[1 2 3; 4 5 6]")     # Notice the strings.

However, most operations return arrays which have to be recast to matrices 
using at best a character with parenthesis:

M = Matrix.Matrix

M(sin(a)) * M(cos(a)).T

The suggestion was made to add ".M" as an attribute of arrays which returns a 
matrix.  Thus, the code above can be written:

sin(a).M * cos(a).M.T

While some aesthestic simplicity is obtained, the big advantage is in 
consistency.  Somebody else may decide that 

P = Matrix.Matrix  is a better choice.  But, if we establish that 

.M  always returns a matrix for arrays < 2d, then we gain consistency.

I've made this change and am ready to commit the change to the Numeric tree, 
unless there are strong objections.   I know some people do not like the 
proliferation of attributes, but in this case the notational convenience it 
affords to otherwise overly burdened syntax and the consistency it allows 
Numeric to deal with Matrix equations may be worth it.

What do you think?

-Travis Oliphant






More information about the NumPy-Discussion mailing list