-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathutility_functions.py
More file actions
40 lines (33 loc) · 1 KB
/
utility_functions.py
File metadata and controls
40 lines (33 loc) · 1 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
"""
@author: Mirco Ceccarelli (mirco.ceccarelli@stud.unifi.it)
@author: Francesco Argentieri (francesco.argentieri@stud.unifi.it)
Università degli Studi di Firenze 2021
"""
import numpy as np
import csv
# Write into csv file.
def write_into_csv(tpr, fpr, file_name):
with open(file_name, 'w') as csv_file:
csv_writer = csv.writer(csv_file, delimiter=',')
csv_writer.writerow(tpr)
csv_writer.writerow(fpr)
# Read from csv file.
def read_from_csv(file_name):
tpr = []
fpr = []
with open(file_name, newline='') as f:
reader = csv.reader(f)
for idx, row in enumerate(reader):
if idx == 0:
for i in row:
tpr.append(float(i))
elif idx == 1:
for i in row:
fpr.append(float(i))
tpr = np.asarray(tpr)
fpr = np.asarray(fpr)
return tpr, fpr
# Write into txt file.
def write_into_table_txt(table, file_name):
with open(file_name, 'w') as f:
f.write(table)