There are two solutions to the A*B*C problem that are not quite comparable, and are not mutually exclusive either.<div><br></div><div>1) allow dot(A,B,C): this would be a great improvement over dot(dot(A,B),C), and it could virtually be done within a day. It is easy to implement, does not require a new syntax, and does not break BC</div>
<div><br></div><div>2) another solution, not incompatible with the first one, is to introduce a new operator in the python language. In the case that it be accepted by the python community at large (which is very unlikely, IMHO), be prepared to a very long time before it is actually implemented. We are talking about several years.</div>
<div><br></div><div>I think that solution 1) is much more realistic than 2) (and again, they are not mutually exclusive, so implementing 1) does not preclude for a future implementation of 2)).</div><div><br></div><div>Implementation of 1) would be quite nice when multiplication of several matrices is concerned.</div>
<div><br></div><div>== Olivier<br><br><div class="gmail_quote">2009/6/7 Tom K. <span dir="ltr"><<a href="mailto:tpk@kraussfamily.org">tpk@kraussfamily.org</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="im"><br>
<br>
Olivier Verdier-2 wrote:<br>
><br>
> There would be a much simpler solution than allowing a new operator. Just<br>
> allow the numpy function dot to take more than two arguments. Then A*B*C<br>
> in<br>
> matrix notation would simply be:<br>
> dot(A,B,C)<br>
><br>
> with arrays. Wouldn't that make everybody happy? Plus it does not break<br>
> backward compatibility. Am I missing something?<br>
><br>
<br>
</div>That wouldn't make me happy because it is not the same syntax as a binary<br>
infix operator.  Introducing a new operator for matrix multiply (and<br>
possibly matrix exponentiation) does not break backward compatibility - how<br>
could it, given that the python language does not yet support the new<br>
operator?<br>
<br>
Going back to Alan Isaac's example:<br>
1)  beta = (X.T*X).I * X.T * Y<br>
2)  beta = np.dot(np.dot(la.inv(np.dot(X.T,X)),X.T),Y)<br>
<br>
With a multiple arguments to dot, 2) becomes:<br>
3)  beta = np.dot(la.inv(np.dot(X.T, X)), X.T, Y)<br>
<br>
This is somewhat better than 2) but not as nice as 1) IMO.<br>
<br>
Seeing 1) with @'s would take some getting used but I think we would adjust.<br>
<br>
For ".I" I would propose that ".I" be added to nd-arrays that inverts each<br>
matrix of the last two dimensions, so for example if X is 3D then X.I is the<br>
same as np.array([inv(Xi) for Xi in X]).  This is also backwards compatible.<br>
With this behavior and the one I proposed for @, by adding preceding<br>
dimensions we are allowing doing matrix algebra on collections of matrices<br>
(although it looks like we might need a new .T that just swaps the last two<br>
dimensions to really pull that off).  But a ".I" attribute and its behavior<br>
needn't be bundled with whatever proposal we wish to make to the python<br>
community for a new operator of course.<br>
<br>
Regards,<br>
   Tom K.<br>
<font color="#888888">--<br>
View this message in context: <a href="http://www.nabble.com/matrix-default-to-column-vector--tp23652920p23910425.html" target="_blank">http://www.nabble.com/matrix-default-to-column-vector--tp23652920p23910425.html</a><br>

</font><div><div></div><div class="h5">Sent from the Numpy-discussion mailing list archive at Nabble.com.<br>
<br>
_______________________________________________<br>
Numpy-discussion mailing list<br>
<a href="mailto:Numpy-discussion@scipy.org">Numpy-discussion@scipy.org</a><br>
<a href="http://mail.scipy.org/mailman/listinfo/numpy-discussion" target="_blank">http://mail.scipy.org/mailman/listinfo/numpy-discussion</a><br>
</div></div></blockquote></div><br></div>