循环遍历事后累积值
假设我有一个数组,
input = [1,2,3,4,5]
我想计算逐元素差异,使得结果数组如下所示:
第一个元素保持不变,
result = [1, ...
第二个元素将是第二个输入元素减去结果向量中当前内容的总和,因此 2-1 = 1
所以最终对于这个特定的输入,你得到
result = [1,1,1,1,1]
我认为使用
[y - x.cumsum[x] for x, y in zip(R, R[1:])]
不起作用或者解决了
np.array(d1)[1:]-np.cumsum(np.array(d1))[:-1]
这也是不正确的。我将不胜感激你的帮助。蒂
Say I have an array
input = [1,2,3,4,5]
I want to calculate the element-wise difference such that the resultant array will be like:
first element stays the same
result = [1, ...
second element will be second input element minus cum sum of whats currently in the result vector so 2-1 = 1
so eventually for this particular input you get
result = [1,1,1,1,1]
I thought about using
[y - x.cumsum[x] for x, y in zip(R, R[1:])]
didn't work alternatively settled on
np.array(d1)[1:]-np.cumsum(np.array(d1))[:-1]
This too is incorrect. I would appreciate your help. ty
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论