-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
31 lines (27 loc) · 916 Bytes
/
utils.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
# -*- coding: utf-8 -*-
"""
Created on Wed Apr 29 15:56:46 2020
@author: kcaldeira
"""
import numpy as np
import csv
def csvWriteVector(csv_file,a_dict):
try:
with open(csv_file, 'w', newline='') as csvfile:
writer = csv.writer(csvfile)
writer.writerow(a_dict.keys())
writer.writerows(zip(*a_dict.values()))
except IOError:
print("I/O error")
def csvWriteScalar(csv_file,a_dict):
try:
with open(csv_file, 'w', newline='') as csvfile:
writer = csv.writer(csvfile)
for key,item in a_dict.items():
if type(item) in [int,float,str]:
writer.writerow([key,item])
elif type(item) in [list, np.ndarray]:
new_item = [key] + item
writer.writerow(new_item)
except IOError:
print("I/O error")