Home Reading Searching Subscribe Sponsors Statistics Posting Contact Spam Lists Links About Hosting Filtering Features Download Marketing Archives FAQ Blog From: Jaakko Luttinen iki.fi> Subject: Dot product of a matrix and an array Newsgroups: gmane.comp.python.scientific.user Date: Friday 17th February 2012 11:04:00 UTC (over 6 years ago) ```Hi! The dot product of a matrix and an array seems to return a matrix. However, this resulting matrix seems to have inconsistent shape. For simplicity, let I be an identity matrix (matrix object) and x a vector (1-d array object). Then np.dot gives wrong dimensions for I*x which causes that one can not compute I*(I*x). See the code below: >>> >>> import numpy as np >>> >>> x = np.arange(5) >>> >>> I = np.asmatrix(np.identity(5)) >>> >>> np.dot(I,x) matrix([[ 0., 1., 2., 3., 4.]]) >>> >>> np.dot(I, np.dot(I,x)) Traceback (most recent call last): File "", line 1, in ValueError: matrices are not aligned I think np.dot(I,x) should return either 1-d vector (array object) or 2-d column vector (array or matrix object), but NOT 2-d row vector because that, in my opinion, is incorrect interpretation of the dot product. Also, I think numpy.dot should return an array object when given an array and a matrix, because the given array might have more than two dimensions (which is okay by the definition of numpy.dot) so the resulting object should be able to handle that. Now numpy.dot seems to give errors in such cases. Best regards, Jaakko```
CD: 12ms