Seperate 2D array to nested list.
Exercise : 2D array --> [[3 items],[1 item]]
1. 2-d array
df_24months.values
>>>
array([[ 2. , 2. , 4. , 3. , 4. , 2. , 3. , 2. , 3. , 1. , 4. ,
2. , 1.5, 3. , 3. , 2.5, 2. , 2. , 1. , 0. , 3.5, 1. ,
1. , 2. ],
[ 2. , 1. , 0. , 1. , 10. , 7. , 3. , 6. , 4. , 7. , 15. ,
10. , 12. , 10. , 5. , 9. , 6. , 5. , 12. , 6. , 4. , 3. ,
1. , 1. ],
[ 6. , 6. , 6. , 14. , 24. , 11. , 10. , 12. , 22. , 8. , 19. ,
10. , 11. , 12. , 4. , 5. , 3. , 4. , 4. , 10. , 3. , 3. ,
8. , 2. ]])
2. Seperate to nested lists.
windows_size=3
target_size = 1
train_set_list = []
for line in df_24months.values:
for start in range(len(line) - (windows_size + target_size - 1)):
i = start
j = start + windows_size
k = start + windows_size + target_size
x_val = line[i: j].tolist()
y_val = line[j: k].tolist()
train_set_list.append([x_val, y_val])
train_set_list[:2]
>>>
[[[2.0, 2.0, 4.0], [3.0]], [[2.0, 4.0, 3.0], [4.0]]]
'Basic Python > Workbook' 카테고리의 다른 글
Latitude VS Longitude (0) | 2023.06.05 |
---|---|
How to get Hydra config without using @hydra.main() (0) | 2022.11.24 |
How to preprocess the article to be neat with Regular Expression (0) | 2022.11.24 |
simple way to merge list (0) | 2022.11.22 |