I was wondering if there is way to read .npy files in Matlab? I know I can convert those to Matlab-style .mat files using scipy.io.savemat
in Python; however I'm more interested in a native or plugin support for .npy files in Matlab.
What is this . NPY file? It is a standard binary file format for persisting a single arbitrary NumPy array on a disk. The format stores all of the shape and data type information necessary to reconstruct the array correctly even on another machine with a different architecture.
Saving the NumPy data into . npy files increases the efficiency of saving and loading data as it is stored in a native binary format. Using . npy files is common for when a particular data set needs to be cleaned, transformed and prepared to be used in the testing of a machine learning model in the future.
This did the job for me, I used it to read npy files.
https://github.com/kwikteam/npy-matlab
If you only want to read .npy file all you need from the npy-matlab project are two files: readNPY.m and readNPYheader.m.
Usage is as simple as:
>> im = readNPY('/path/to/file.npy');
There is a c++ library available https://github.com/rogersce/cnpy
You could write a mex function to read the data. I would prefer to store everything in hdf5
A quick way would be to read it in python, as below,
data = np.load('/tmp/123.npz')
Then save it as '.csv', again by python, using python documentation or,
numpy.savetxt('FileName.csv', arrayToSave)
(more documentation here)
Finally, you can read it in MATLAB using the following command,
csvread()
Quick Update:
As the user "Ender" mentioned in the comments, the csvread()
is now deprecated and readmatrix()
stands in its lieu. (documentation)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With