【发布时间】:2020-03-28 10:41:19
【问题描述】:
我正在尝试将标量列表与数组相乘,但出现广播错误。
解决这个问题并获得三个不同的数组的pythonic方法是什么,每个数组都由lst的每个数字缩放?
import numpy as np
ar = np.array([2, 3, 1, 0,5,6,9,20,10,15,1,54,20,10,40,50,60, 49,2,40]).reshape(10,2)
scale = 2
lst = [4,5,6]
lst * ar
Out: ValueError: operands could not be broadcast together with shapes (3,) (10,2)
【问题讨论】:
-
将 (3,1,1) 形状与 (1,10,2) 相乘将产生 (3,10,2)
标签: python arrays python-3.x list numpy