Help us understand the problem. What is going on with this article?

[Tips]1階差分の計算と逆変換 [python/numpy]

More than 1 year has passed since last update.

調べてみてnumpyの関数で簡単に実現できることがわかったので、そのメモ。

 import numpy as np

"""
1階差分
"""
x = np.array(range(10, 100)) # 適当なベクトル

x0 = x[0] # 初期値を保存
x_diff1 = np.diff(x)

"""
逆変換
"""
tmp = np.concatenate(([x0], x_diff1))
# または以下
# tmp = np.r_[x[0],x_diff1]
x_ = np.cumsum(tmp)

"""
チェック
"""
np.all(x == x_)

だいたいのことはnumpyの関数がなんとかしてくれますね。未だに馴染めないけど徐々に覚えていきたい。

雑記

この前処理も含めてstatsmodelsをsckit-learnのpipelineに流して綺麗に実装しようと思っているけど、微妙にインタフェースが合わないのが歯がゆい。
pipelineに乗せることで、ロジックの変更(パラメータ変更や実行順序の入れ替え、手法そのものの変更とか)に柔軟性が出ることを期待してるのですが、すんなりとは行かないものか。

楽なやり方があれば知りたい。。

参考

http://qiita.com/sotetsuk/items/d0e73afdcffdc8ac3e6b

Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away