我有一个 NumPy 数组,我想累积一列的值,比如第二列。
a = np.array([[1,2],[2,4]])
# some kind of accumulate function that accumulates just one column:
np.add.accumulate(a, 2)
a
现在应该是 [[1,2],[2,6]]
有没有办法在 NumPy 中做到这一点?
最佳答案
a = np.array([[1,2],[2,4]])
np.add.accumulate(a[:,1], out=a[:,1])
a
现在是:
array([[1, 2],
[2, 6]])
关于python - 仅累积一列的 numpy 数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5176968/