[英]ValueError: shapes (3,3,1) and (3,1) not aligned: 1 (dim 2) != 3 (dim 0)
I am trying to multiply some matrices in python, using the np.dot function.I have a three by three array that I want to multiply by a three by one我正在尝试使用 np.dot function 将 python 中的一些矩阵相乘。我有一个三乘三的数组,我想将其乘以三乘一
ValueError: shapes (3,3,1) and (3,1) not aligned: 1 (dim 2) != 3 (dim 0) ValueError:形状 (3,3,1) 和 (3,1) 未对齐:1 (dim 2) != 3 (dim 0)
What exactly does the third dimension on the array mean?数组的第三维到底是什么意思? Is there a way to get rid of it?
有没有办法摆脱它?
A (3,3,1) means that you have a vector of 3 two dimensional vectors. A (3,3,1) 表示您有一个包含 3 个二维向量的向量。 Take this as example:
以此为例:
a = np.random.rand(3,3,1)
print(a)
[[[0.08233029]
[0.21532053]
[0.88495997]]
[[0.59743708]
[0.97966668]
[0.44927175]]
[[0.40792714]
[0.85891152]
[0.22584841]]]
As above, there are 3 vectors of two dimensions with 3 numbers in a vector.如上,有3个二维向量,一个向量中有3个数。 In order to remove it, just use
np.reshape
to do the trick.为了删除它,只需使用
np.reshape
即可。
a = np.reshape(a, [3,3])
print(a)
[[0.08233029 0.21532053 0.88495997]
[0.59743708 0.97966668 0.44927175]
[0.40792714 0.85891152 0.22584841]]
From here onwards, you can do your np.dot
to obtain your result从这里开始,你可以做你的
np.dot
来获得你的结果
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.