Python 如何在 Matlab 中读取 .npy 文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 
原文地址: http://stackoverflow.com/questions/21553999/
Warning: these are provided under cc-by-sa 4.0 license.  You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to read .npy files in Matlab
提问by John Manak
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.savematin Python; however I'm more interested in a native or plugin support for .npy files in Matlab.
我想知道是否有办法在 Matlab 中读取 .npy 文件?我知道我可以使用scipy.io.savematPython将它们转换为 Matlab 风格的 .mat 文件;但是我对 Matlab 中 .npy 文件的本机或插件支持更感兴趣。
采纳答案by Daniel
There is a c++ library available https://github.com/rogersce/cnpy
有一个 C++ 库可用https://github.com/rogersce/cnpy
You could write a mex function to read the data. I would prefer to store everything in hdf5
您可以编写一个 mex 函数来读取数据。我宁愿将所有内容都存储在 hdf5 中
回答by miluz
This did the job for me, I used it to read npy files.
这对我有用,我用它来读取 npy 文件。
https://github.com/kwikteam/npy-matlab
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.
如果您只想读取 .npy 文件,那么您只需要从 npy-matlab 项目中读取两个文件:readNPY.m 和 readNPYheader.m。
Usage is as simple as:
用法很简单:
>> im = readNPY('/path/to/file.npy');
回答by Hossein Rahimi
A quick way would be to read it in python, as below,
一种快速的方法是在 python 中读取它,如下所示,
data = np.load('/tmp/123.npz')
Then save it as '.csv', again by python, using python documentationor,
然后将其保存为“.csv”,再次通过 python,使用python 文档,或者,
numpy.savetxt('FileName.csv', arrayToSave)
(更多文档在这里)
Finally, you can read it in MATLAB using the following command,
最后,您可以使用以下命令在 MATLAB 中读取它,
csvread()

