x = np.arange(10) condlist = [x in [2,3,4], x>5] choicelist = [x, x**2] np.select(condlist, choicelist)
有办法让它工作吗?
你应该使用 isin 取而代之的是:
isin
x = np.arange(10) condlist = [np.isin(x, [2,3,4]), x>5] choicelist = [x, x**2] np.select(condlist, choicelist)
array([ 0, 0, 2, 3, 4, 0, 36, 49, 64, 81])