Fre*_*Foo 14
您可能已将矩阵表示为数组.您可以将它们转换为矩阵np.asmatrix,或者用于np.dot矩阵乘法:
>>> X = np.random.rand(15 * 7).reshape((15, 7))
>>> X.T * X
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: operands could not be broadcast together with shapes (7,15) (15,7)
>>> np.dot(X.T, X).shape
(7, 7)
>>> X = np.asmatrix(X)
>>> (X.T * X).shape
(7, 7)
Run Code Online (Sandbox Code Playgroud)
数组和矩阵之间的一个区别是*矩阵是矩阵乘积,而阵列则是元素乘积.