In [1]:
import pandas as pd
import numpy as np
import math
%matplotlib inline
In [2]:
# サイクルあたりのステップ数
steps_per_cycle = 50
# 生成するサイクル数
number_of_cycles = 100
In [3]:
df = pd.DataFrame(np.arange(steps_per_cycle * number_of_cycles + 1), columns=["t"])
df.head()
Out[3]:
In [4]:
df["sin_t"] = df.t.apply(lambda x: math.sin(x * (2 * math.pi / steps_per_cycle)))
In [5]:
df[["sin_t"]].plot()
Out[5]:
In [6]:
df[["sin_t"]].head(steps_per_cycle * 2).plot()
Out[6]:
In [7]:
df["sin_t+1"] = df["sin_t"].shift(-1)
In [8]:
df.tail()
Out[8]:
In [9]:
df.dropna(inplace=True)
df.tail()
Out[9]:
In [10]:
df[["sin_t", "sin_t+1"]].head(steps_per_cycle).plot()
Out[10]:
In [11]:
matrix = df[["sin_t", "sin_t+1"]].as_matrix()
matrix
Out[11]:
In [12]:
np.save("normal.npy", matrix)
In [ ]: