【发布时间】:2018-06-08 10:03:46
【问题描述】:
数组具有以下维度:
dists: (500,5000)
train: (5000,)
test:(500,)
为什么前两个语句会抛出错误,而第三个却可以正常工作?
dists += train + test
错误:ValueError: operands could not be broadcast together with shapes (5000,) (500,)
dists += train.reshape(-1,1) + test.reshape(-1,1)
错误:ValueError: operands could not be broadcast together with shapes (5000,1) (500,1)
-
dists += train + test.reshape(-1,1)这很好用!
为什么会这样?
【问题讨论】:
标签: python python-3.x numpy array-broadcasting