-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCSV_vectorWriter.py
More file actions
54 lines (32 loc) · 1.18 KB
/
CSV_vectorWriter.py
File metadata and controls
54 lines (32 loc) · 1.18 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
'''
* CSV_vectorWriter.py
*
* Created on: 15.02.2019
* Author: Andrew Jason Bishop
*
* General description:
* https://realpython.com/python-csv/
'''
import csv
class CSV_vectorWriter:
def __init__(self):
self.vectorLength = 1
def setVectorLength(self, _N):
self.vectorLength = _N
def writeVectorsToFile(self, _vectors ,\
_fileAccessMode ,\
_fileName = 'default.csv'):
with open( _fileName, mode = _fileAccessMode ) as out_file:
csv_writer = csv.writer( out_file, delimiter=',' )
self.writeVectors( _vectors, csv_writer )
print("file", _fileName, "successfully written")
def writeVectors(self, _vectors, _writer):
if self.isSingleVector( _vectors ):
_vectors = self.expandVectorDimension( _vectors )
for vector in _vectors:
_writer.writerow( vector )
def isSingleVector(self, _DUT):
return ( 1 == len(_DUT.shape) )
def expandVectorDimension(self, _singleVector):
return np.expand_dims(_singleVector, axis=0)
''' END '''