[Numpy-discussion] matrix default to column vector?

Tom K. tpk at kraussfamily.org
Sun Jun 7 08:20:17 EDT 2009

Olivier Verdier-2 wrote:
> There would be a much simpler solution than allowing a new operator. Just
> allow the numpy function dot to take more than two arguments. Then A*B*C
> in
> matrix notation would simply be:
> dot(A,B,C)
> with arrays. Wouldn't that make everybody happy? Plus it does not break
> backward compatibility. Am I missing something?

That wouldn't make me happy because it is not the same syntax as a binary
infix operator.  Introducing a new operator for matrix multiply (and
possibly matrix exponentiation) does not break backward compatibility - how
could it, given that the python language does not yet support the new

Going back to Alan Isaac's example:
1)  beta = (X.T*X).I * X.T * Y 
2)  beta = np.dot(np.dot(la.inv(np.dot(X.T,X)),X.T),Y) 

With a multiple arguments to dot, 2) becomes:
3)  beta = np.dot(la.inv(np.dot(X.T, X)), X.T, Y)

This is somewhat better than 2) but not as nice as 1) IMO.

Seeing 1) with @'s would take some getting used but I think we would adjust.

For ".I" I would propose that ".I" be added to nd-arrays that inverts each
matrix of the last two dimensions, so for example if X is 3D then X.I is the
same as np.array([inv(Xi) for Xi in X]).  This is also backwards compatible. 
With this behavior and the one I proposed for @, by adding preceding
dimensions we are allowing doing matrix algebra on collections of matrices
(although it looks like we might need a new .T that just swaps the last two
dimensions to really pull that off).  But a ".I" attribute and its behavior
needn't be bundled with whatever proposal we wish to make to the python
community for a new operator of course.

   Tom K.
View this message in context: http://www.nabble.com/matrix-default-to-column-vector--tp23652920p23910425.html
Sent from the Numpy-discussion mailing list archive at Nabble.com.

More information about the NumPy-Discussion mailing list