0

Im trying to store 60 values to x and the next one to the y and then shift it 1 up and store 60 values to x and the next one to the y. But the for loop only works once for the x values the y values some how do get stored properly. And the size of my dataset is not the problem as storing the y values work. It's just the x values that don't store and when debugging the x sets are just empty array's except the first one. What am i doing wrong?

import math
import numpy as np
import pandas as pd

df = pd.read_csv('dataset.csv')

print(df)

dataset = df.values

data_len = math.ceil(len(dataset) * .1)

data = dataset[0:data_len , :]
print(data)

x = []
y = []

for i in range(60, len(data)):
    x.append(data[60-i:i, 0])
    y.append(data[i, 0])
bas.cmd
  • 45
  • 5

1 Answers1

0

I think that you should try to avoid using a for loop, in numpy it is often faster to create masks and work with that. If i understand your question correctly, you want to store 0-59 in x, then 60 in y, then 61-119 in x, then 120 in y and so on.

If that is the correct understanding i would try this instead:

dataset = np.random.randint(1,1000,size=1000) #generating an example

mask = np.zeros(len(dataset),dtype=np.bool)
mask[60::60] = 1 #indices of the ys

y = dataset[mask]
x = dataset[~mask]
Christian Sloper
  • 7,440
  • 3
  • 15
  • 28