如果我有一个数组,假设:np.array([4,8,-2,9,6,0,3,-6])
并且我想将上一个数字添加到下一个元素中,我该怎么做?
每次数字0显示添加元素“restarts”。在
以上面的数组为例,我在运行函数时应该得到以下输出:
如果在事务中插入上述数组,stock = np.array([4,12,10,19,25,0,3,-3])
是正确的输出。在
def cumulativeStock(transactions):
# insert your code here
return stock
我想不出解决这个问题的方法。任何帮助都将不胜感激。在
另一种矢量化解决方案:
我相信你的意思是这样的?在
相关问题 更多 >
编程相关推荐