Python-Numpy: operands could not be broadcast together with shapes

BUG样式:

ValueError: operands could not be broadcast together with shapes (353,) (355,) 

举个栗子:

import numpy

numpy_a=numpy.array([1, 2, 3, 4, 5])
numpy_b=numpy.array([1, 2, 3])

print(numpy_a + numpy_b)

原因:numpy_a与numpy_b的shape不同, 违反了ufunc的广播机制, 所以报错,解决方法。维度调成相同即可

如果大家不知道numpy多维数组的概念,特点,以及使用方法,主页有介绍,祝大家生活愉快!

猜你喜欢

转载自blog.csdn.net/Odyssues_lee/article/details/85244735
今日推荐