-
Notifications
You must be signed in to change notification settings - Fork 15
/
Data.py
38 lines (27 loc) · 1.03 KB
/
Data.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from torch.utils.data import Dataset
import numpy as np
class NextDateDataset(Dataset):
def __init__(self, dates):
dates = [date.split(",") for date in dates]
convert_int = lambda dt: list(map(int, dt))
self.dates = [convert_int(date) for date in dates]
#print(dates)
def __len__(self):
return len(self.dates)-1
def __getitem__(self, idx):
return np.array(self.dates[idx]).astype(np.float32), np.array(self.dates[idx+1]).astype(np.float32)
class TimeDateDataset(Dataset):
def __init__(self, dates):
dates = [date.split(",") for date in dates]
convert_int = lambda dt: list(map(int, dt))
self.dates = [convert_int(date) for date in dates]
#print(dates)
def __len__(self):
return len(self.dates)-1
def __getitem__(self, idx):
x = np.array(self.dates[idx]).astype(np.float32)
return x, x
if __name__ == "__main__":
dt = open("dates.txt", 'r').readlines()
dataset = NextDateDataset(dt)
print(dataset[0])