仅累积一列的numpy数组 [英] accumulate numpy array for just one column
本文介绍了仅累积一列的numpy数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个NumPy数组,我想累加一列的值,例如2 nd 列.
I have a NumPy array, i want to accumulate the values of one column, say the 2nd column.
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中有办法做到这一点吗?
Is there a way to do this in NumPy?
推荐答案
a = np.array([[1,2],[2,4]])
np.add.accumulate(a[:,1], out=a[:,1])
a
现在是:
array([[1, 2],
[2, 6]])
这篇关于仅累积一列的numpy数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文