csv_to_numpy_fuzzy.py
2.2 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import numpy as np
import pandas as pd
import const
import math
csv = pd.read_csv("./fuzzy_normal_dataset.csv")
arr = []
idx = 0
while idx < 10000 and idx < len(csv):
now_row = csv.iloc[idx].tolist()
data_len = now_row[1]
for row_idx in range(data_len + 3, len(now_row)):
now_row[row_idx] = '00'
del now_row[1]
arr.append(now_row)
idx += 1
if idx % 1000 == 0:
print(idx)
arr = np.array(arr)
np.save('./fuzzy_normal_numpy.npy', arr)
save_load = np.load('./fuzzy_normal_numpy.npy')
print(len(save_load))
print(save_load[0])
csv = pd.read_csv("./fuzzy_abnormal_dataset.csv")
arr = []
idx = 0
while idx < 10000 and idx < len(csv):
now_row = csv.iloc[idx].tolist()
data_len = now_row[1]
for row_idx in range(data_len + 3, len(now_row)):
now_row[row_idx] = '00'
del now_row[1]
arr.append(now_row)
idx += 1
if idx % 1000 == 0:
print(idx)
arr = np.array(arr)
np.save('./fuzzy_abnormal_numpy.npy', arr)
# for packet number = 1
csv = pd.read_csv("./fuzzy_normal_dataset.csv")
arr = []
idx = 0
while idx < 10000 and idx < len(csv):
packet = np.zeros((1, const.CAN_DATA_LEN * 1))
for next_i in range(1):
data_len = int(csv.iloc[idx + next_i, 1])
for j in range(data_len):
data_value = int(csv.iloc[idx + next_i, 2 + j], 16) / 255.0
packet[0][j + const.CAN_DATA_LEN * next_i] = data_value
arr.append(packet)
idx += 1
if idx % 1000 == 0:
print(idx)
arr = np.array(arr)
np.save('./fuzzy_tensor_normal_numpy.npy', arr)
save_load = np.load('./fuzzy_tensor_normal_numpy.npy')
print(len(save_load))
print(save_load[0])
# for packet number = 1
csv = pd.read_csv("./fuzzy_abnormal_dataset.csv")
arr = []
idx = 0
while idx < 10000 and idx < len(csv):
packet = np.zeros((1, const.CAN_DATA_LEN * 1))
for next_i in range(1):
data_len = int(csv.iloc[idx + next_i, 1])
for j in range(data_len):
data_value = int(csv.iloc[idx + next_i, 2 + j], 16) / 255.0
packet[0][j + const.CAN_DATA_LEN * next_i] = data_value
arr.append(packet)
idx += 1
if idx % 1000 == 0:
print(idx)
arr = np.array(arr)
np.save('./fuzzy_tensor_abnormal_numpy.npy', arr)