简体   繁体   中英

How to load .mat files in python without scipy.io?

I need to load.mat files in python arrays. I have tried the scipy.io method but it's changing the values of the array loaded by scaling it down. What is the best way to load.mat files in python and then use them to train a neural network? Thank you

To write a matrix to a file in MATLAB, I use the command

writematrix(A)

Where A is the matrix in question. This will write the matrix to a.txt file in the working directory that will be called "A.txt". If you only have a.mat file, you can load it in to MATLAB so you can write it to a text file with the load command:

A=load('myFile.mat')

Then you can use the writematrix command. This command will produce a text file with each line corresponding to a row in the matrix, with entries of different columns delimited by commas. To load this in with python, you can use the numpy.loadtxt command:

A = np.loadtxt("A.txt",delimiter=',')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM