Skip to content

Instantly share code, notes, and snippets.

@kmcelwee
Created January 23, 2020 20:24
Show Gist options
  • Save kmcelwee/339e009c076f511e5b01a54a49e1f632 to your computer and use it in GitHub Desktop.
Save kmcelwee/339e009c076f511e5b01a54a49e1f632 to your computer and use it in GitHub Desktop.
def data_transform(data, timesteps, var='x'):
m = []
s = data.to_numpy()
for i in range(s.shape[0]-timesteps):
m.append(s[i:i+timesteps].tolist())
if var == 'x':
t = np.zeros((len(m), len(m[0]), len(m[0][0])))
for i, x in enumerate(m):
for j, y in enumerate(x):
for k, z in enumerate(y):
t[i, j, k] = z
else:
t = np.zeros((len(m), len(m[0])))
for i, x in enumerate(m):
for j, y in enumerate(x):
t[i, j] = y
return t
all_y_rnn = data_transform(all_y, HOURS_AHEAD, var='y')
all_X_rnn = data_transform(all_X, HOURS_AHEAD, var='x')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment