0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

numpyで逆順の累計を求める

Posted at
import numpy as np

def rcumsum(array, axis=0):
    s = tuple([slice(None,None,-1)] * axis + slice(None))
    return np.cumsum(array.__getitem__(s), axis=axis).__getitem__(s)

要するに、np.cumsum(array[:,::-1], axis=1)[:,::-1]などとすれば良いだけの話なのですが、汎用的な処理にするためにスライスオブジェクトを使っています。numpyでは妙にsliceオブジェクトを多用しています。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?