How to read .npy files in Matlab

房东的猫 提交于 2021-01-18 07:46:25

问题


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.


回答1:


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




回答2:


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');



回答3:


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()


来源:https://stackoverflow.com/questions/21553999/how-to-read-npy-files-in-matlab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!