Beh*_*adi 2 python numpy matrix
我有1X2矩阵,Mu_I.transpose()和2x2矩阵,Covariance_I_Inverse.
乘法的结果应该是1x2矩阵,但我的输出是2x2矩阵.
为什么?如何获得1x2矩阵?
>>> Mu_I.transpose()
[[ 10.02010924 9.99184818]]
>>> Mu_I.transpose().shape
(1, 2)
>>> Covariance_I_Inverse
[[ 0.72006911 0. ],
[ 0. 0.77689697]]
>>> Covariance_I_Inverse.shape
(2, 2)
>>> (Mu_I.transpose()*Covariance_I_Inverse)
[[ 7.21517113 0. ],
[ 0. 7.76263658]]
>>> (Mu_I.transpose()*Covariance_I_Inverse).shape
(2, 2)
Run Code Online (Sandbox Code Playgroud)
我猜这些变量是numpy.array,但不是numpy.matrix.因为numpy.array,*被定义为逐元素乘法.在那种情况下使用numpy.dot().这将为您提供矩阵乘法.
或者干脆使用numpy.matrix和* operator将矩阵乘法.