forked from Conchylicultor/DeepLearningOnGraph
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnpy_to_mat.py
More file actions
44 lines (34 loc) · 1.17 KB
/
Copy pathnpy_to_mat.py
File metadata and controls
44 lines (34 loc) · 1.17 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
"""
Convert the .npy into .mat (for plotting into matlab)
Just indicate the input and output directory.
Use python 3 (but should be working with python 2)
"""
import os, sys
import numpy as np
import scipy.io as sio
import utils
# Set directories
root = os.getcwd()
#dirDataIn = root + '/../Data/Meshs/'
dirDataIn = root + '/../Data/Test_mesh_01/samples/'
dirDataOut = root + '/../Data/Test_mesh_01/samples_mat/'
savedVariableName = 'y'
def main():
# Global check
assert(os.path.exists(dirDataIn))
assert(os.path.exists(dirDataOut))
# For each file
filesList = os.listdir(dirDataIn)
for filename in filesList:
print('Try converting ', filename)
name = filename.split('.')[0] # Little hack to get the filename
if filename.endswith('.npy'): # Candidate
matrix = np.load(dirDataIn + filename, fix_imports = True)
elif filename.endswith('.txt'): # Candidate
matrix = utils.loadLabelList(dirDataIn + filename)
else:
print('Wrong format, skiped')
continue
sio.savemat(dirDataOut + name + '.mat', {savedVariableName:matrix})
if __name__ == "__main__":
main()