[SciPy-User] Dot product of a matrix and an array
Pauli Virtanen
pav@iki...
Fri Feb 17 05:16:01 CST 2012
Hi,
17.02.2012 12:04, Jaakko Luttinen kirjoitti:
[clip]
> >>> 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 "<stdin>", line 1, in <module>
> 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.
Yep, that's inconsistent behavior. What probably happens is that
np.dot(I, x) -> np.asmatrix(np.dot(np.asarray(I), x))
As you can maybe deduce, the matrix class is not as heavily used as the
arrays...
http://projects.scipy.org/numpy/ticket/2057
--
Pauli Virtanen
More information about the SciPy-User
mailing list