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:<div><br></div><div>dot(A,B,C)</div><div>
<br></div><div>with arrays. Wouldn't that make everybody happy? Plus it does not break backward compatibility. Am I missing something?</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>
Fernando Perez wrote:<br>
><br>
> On Sat, Jun 6, 2009 at 11:03 AM, Charles R<br>
> Harris<<a href="mailto:charlesr.harris@gmail.com">charlesr.harris@gmail.com</a>> wrote:<br>
><br>
>> I don't think we can change the current matrix class, to do so would<br>
>> break<br>
>> too much code. It would be nice to extend it with an explicit inner<br>
>> product,<br>
>> but I can't think of any simple notation for it that python would parse.<br>
><br>
> Maybe it's time to make another push on python-dev for the pep-225<br>
> stuff for other operators?<br>
><br>
> <a href="https://cirl.berkeley.edu/fperez/static/numpy-pep225/" target="_blank">https://cirl.berkeley.edu/fperez/static/numpy-pep225/</a><br>
><br>
> Last year I got pretty much zero interest from python-dev on this, but<br>
> they were very very busy with 3.0 on the horizon. Perhaps once they<br>
> put 3.1 out would be a good time to champion this again.<br>
><br>
> It's slightly independent of the matrix class debate, but perhaps<br>
> having special operators for real matrix multiplication could ease<br>
> some of the bottlenecks of this discussion.<br>
><br>
> It would be great if someone could champion that discussion on<br>
> python-dev though, I don't see myself finding the time for it another<br>
> time around...<br>
><br>
<br>
</div>How about pep 211?<br>
<a href="http://www.python.org/dev/peps/pep-0211/" target="_blank">http://www.python.org/dev/peps/pep-0211/</a><br>
<br>
PEP 211 proposes a single new operator (@) that could be used for matrix<br>
multiplication.<br>
MATLAB has elementwise versions of multiply, exponentiation, and left and<br>
right division using a preceding "." for the usual matrix versions (* ^ \<br>
/).<br>
PEP 225 proposes "tilde" versions of + - * / % **.<br>
<br>
While PEP 225 would allow a matrix exponentiation and right divide, I think<br>
these things are much less common than matrix multiply. Plus, I think<br>
following through with the PEP 225 implementation would create a<br>
frankenstein of a language that would be hard to read.<br>
<br>
So, I would argue for pushing for a single new operator that can then be<br>
used to implement "dot" with a binary infix operator. We can resurrect PEP<br>
211 or start a new PEP or whatever, the main thing is to have a proposal<br>
that makes sense. Actually, what do you all think of this:<br>
@ --> matrix multiply<br>
@@ --> matrix exponentiation<br>
and we leave it at that - let's not get too greedy and try for matrix<br>
inverse via @/ or something.<br>
<br>
For the nd array operator, I would propose taking the last dimension of the<br>
left array and "collapsing" it with the first dimension of the right array,<br>
so<br>
shape (a0, ..., aL-1,k) @ (k, b0, ..., bM-1) --> (a0, ..., aL-1, b0, ...,<br>
bM-1)<br>
Does that make sense?<br>
<br>
With this proposal, matrices go away and all our lives are sane again. :-)<br>
Long live the numpy ndarray! Thanks to the creators for all your hard work<br>
BTW - I love this stuff!<br>
<br>
- Tom K.<br>
<font color="#888888">--<br>
View this message in context: <a href="http://www.nabble.com/matrix-default-to-column-vector--tp23652920p23907204.html" target="_blank">http://www.nabble.com/matrix-default-to-column-vector--tp23652920p23907204.html</a><br>
</font><div class="im">Sent from the Numpy-discussion mailing list archive at Nabble.com.<br>
<br>
_______________________________________________<br>
</div><div><div></div><div class="h5">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>