“操作数不能一起广播”,即使维度是相同的

2024-04-27 19:09:21 发布

您现在位置:Python中文网/ 问答频道 /正文

所以我的代码遇到了一个非常奇怪的问题。问题是:

vrt = np.matrix.transpose(vr) #np.shape(vrt) = (1832,360)
term2 = C*np.cos((beta*np.pi/180)-azrad) #np.shape(term2) = (1832,360)
test = np.shape(vrt) == np.shape(term2) #test = True
ci = vrt - term2

ValueError: operands could not be broadcast together with shapes (360,1832) (1832,360)

这两个数组的大小相同(test=True),但当我尝试减去这两个矩阵时,它现在表示第一个矩阵不再是(1832360)。当我在不使用vr转置的情况下尝试此操作时,显然test=False,但错误完全相同(ValueError:操作数不能与shapes(3601832)(1832360))一起广播)。你知道吗


Tags: 代码testtruenp矩阵cosmatrixbeta