-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpreprocesser.py
More file actions
48 lines (39 loc) · 1.26 KB
/
preprocesser.py
File metadata and controls
48 lines (39 loc) · 1.26 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
import numpy as np
# open txt file and read the content
def read_points_file(file_path):
arr = []
arr2 = []
params = []
consider_next = True
with open(file_path, 'r') as file:
for idx, line in enumerate(file):
if line == "START\n":
consider_next = False
continue
if line == "END\n" or line == "END":
consider_next = True
continue
if consider_next:
arr.append(line.split(' '))
# print(line)
else:
print("Not considering line: ", line)
consider_next = True
# remove empty strings
for elem in arr:
for small_elem in elem:
if small_elem == '':
elem.remove(small_elem)
# remove '\n' from the end of the string if it exists
elem[-1] = elem[-1].replace('\n', '')
for elem in arr:
arr2.append([float(i) for i in elem])
params = np.array([elem[:-1] for elem in arr2])
flat_params = []
for elem in params:
for small_elem in elem:
flat_params.append(small_elem)
return flat_params
if __name__ == "__main__":
output = read_points_file("points.txt")
print(output)