简体   繁体   English

ValueError:形状 (3,3,1) 和 (3,1) 未对齐:1 (dim 2) != 3 (dim 0)

[英]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.

相关问题 ValueError:形状(4,1)和(3,1)未对齐:1(dim 1)!= 3(dim 0) - ValueError: shapes (4,1) and (3,1) not aligned: 1 (dim 1) != 3 (dim 0) ValueError:形状(50,50)和(3,1)不对齐:50(dim 1)!= 3(dim 0) - ValueError: shapes (50,50) and (3,1) not aligned: 50 (dim 1) != 3 (dim 0) 显示 ValueError:形状 (1,2) 和 (3,1) 未对齐:2 (dim 1) != 3 (dim 0) - Showing ValueError: shapes (1,2) and (3,1) not aligned: 2 (dim 1) != 3 (dim 0) 多项式回归:ValueError:形状(88,1)和(3,1)未对齐:1(dim 1)!= 3(dim 0) - Polynomial Regression :ValueError: shapes (88,1) and (3,1) not aligned: 1 (dim 1) != 3 (dim 0) ValueError: 形状 (2,) 和 (5,) 未对齐:2 (dim 0) != 5 (dim 0) - ValueError: shapes (2,) and (5,) not aligned: 2 (dim 0) != 5 (dim 0) ValueError:形状(3,)和(0,)未对齐:3(dim 0)!= 0(dim 0) - ValueError: shapes (3,) and (0,) not aligned: 3 (dim 0) != 0 (dim 0) ValueError:形状和未对齐:(dim 2)!= 4(dim 0) - ValueError: shapes and not aligned: (dim 2) != 4 (dim 0) ValueError:形状 (3,) 和 (4,) 未对齐:3 (dim 0) != 4 - ValueError: shapes (3,) and (4,) not aligned: 3 (dim 0) != 4 ValueError: 形状 (62,6) 和 (5,) 未对齐:6 (dim 1) != 5 (dim 0) - ValueError: shapes (62,6) and (5,) not aligned: 6 (dim 1) != 5 (dim 0) ValueError:形状(2,2)和(4,6)不对齐:2(dim 1)!= 4(dim 0) - ValueError: shapes (2,2) and (4,6) not aligned: 2 (dim 1) != 4 (dim 0)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM