1
假设我们创建numpy的阵列是这样的:蟒 - numpy的 - 不同尺寸的numpy的阵列求和
x = np.linspace(1,5,5).reshape(-1,1)
这导致这样的:
array([[ 1.],
[ 2.],
[ 3.],
[ 4.],
[ 5.]])
现在我们添加此阵列的转置它:
x + x.T
导致此:
array([[ 2., 3., 4., 5., 6.],
[ 3., 4., 5., 6., 7.],
[ 4., 5., 6., 7., 8.],
[ 5., 6., 7., 8., 9.],
[ 6., 7., 8., 9., 10.]])
我不明白这是因为两个数组有不同的维数(5x1和1x5),并且我在线性代数中学习到我们只能在矩阵具有相同维数时求和。
编辑:好,谢谢,明白了
请'broadcasting'读了做 - https://docs.scipy.org/doc/numpy- 1.13.0 /用户/ basics.broadcasting.html。 – Divakar
可能重复的[numpy的数组广播规则(https://stackoverflow.com/questions/11178179/numpy-array-broadcasting-rules) – FTP
而不是添加的“编辑:好,谢谢,明白了”你的问题,请注明答案(如下)是正确的。 –