
On Fri, 13 Jan 2006, "Paulo J. S. Silva" apparently wrote:
I was playing with the matrix type in numpy and I felt the "need" to have the "dot" function returning a 1x1 matrix as a scalar.
import numpy as N x = N.mat(range(10)) x matrix([[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]]) x*x.T matrix([[285]]) 285*x matrix([[ 0, 285, 570, 855, 1140, 1425, 1710, 1995, 2280, 2565]]) (x*x.T)*(x.T*x) Traceback (most recent call last): File "<stdin>", line 1, in ? File "C:\Python24\Lib\site-packages\numpy\core\defmatrix.py", line 128, in __m
Since a 1x1 matrix is not a scalar, the current behavior is desirable, IMO. Specifically, I want an error in the last example below, since otherwise matrix multiplication will not be associative. Cheers, Alan Isaac PS Current behavior: Python 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. ul__ return N.dot(self, other) ValueError: objects are not aligned