After investigating, I found that it can be easily realized with the numpy function, so that memo.
import numpy as np
"""
1st floor difference
"""
x = np.array(range(10, 100)) #Suitable vector
x0 = x[0] #Save initial value
x_diff1 = np.diff(x)
"""
Inverse conversion
"""
tmp = np.concatenate(([x0], x_diff1))
#Or below
# tmp = np.r_[x[0],x_diff1]
x_ = np.cumsum(tmp)
"""
check
"""
np.all(x == x_)
For the most part, numpy's functions do the trick. I'm still not familiar with it, but I want to gradually remember it.
I'm planning to run stats models in the sckit-learn pipeline, including this pre-processing, and implement it neatly, but it's awkward that the interface does not fit subtly. I'm hoping that by putting it on the pipeline, the logic changes (parameter changes, execution order changes, method changes, etc.) will be more flexible, but isn't it going smoothly?
I want to know if there is an easy way. ..
http://qiita.com/sotetsuk/items/d0e73afdcffdc8ac3e6b
Recommended Posts