我试图修改下面的代码,以便它将与之相关的indexes
和Numbers
值相加
因此,由于indexes
中的第一个元素是3,它取Numbers
中的前3个元素,即1, 5, 6
所有这些整数的和等于12
对于下一个5个元素中的第二个值,将计算7,4,3,6,7
,该值等于27
我试图实现Expected Output
,但是得到了Current Output
。我可以在代码中更改什么来实现Expected Output
,而不使用for循环
Numbers = np.array([1, 5, 6,7,4,3,6,7,11,3,4,6,2,20])
indexes = np.array([3 , 5, 5])
np.add.reduceat(Numbers, indexes)
电流输出:
array([11, 3, 62])
预期产量
array([12, 27, 26])
按累积和对索引,然后将其提供给
reduceat
调整“indexes”变量以表示箱子而不是增量
相关问题 更多 >
编程相关推荐