Am Samstag, 12. Mai 2012 19:17:03 UTC+2 schrieb Stefan Krastanov:
If we do this it would be possible to write stuff like `eye(2)*[x, y]`
and it will work.
This could be implemented in Matrix.__mul__ and __rmul__. However, I'm not really sure it's a good idea.
In numpy we have this behavior:
>>> from numpy import *
>>> a = matrix([[1,2],[3,4]])
>>> a*[1,-1]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/site-packages/numpy/matrixlib/defmatrix.py", line 330, in __mul__
return N.dot(self, asmatrix(other))
ValueError: objects are not aligned
>>> [1,-1]*a
matrix([[-2, -2]])
>>> a = array([[1,2],[3,4]])
>>> [1,-1]*a
array([[ 1, -2],
[ 3, -4]])
>>> a*[1,-1]
array([[ 1, -2],
[ 3, -4]])
So it treats [1, -1] as a row vector.
Vinzent