How do read .npy files in matlab?

586 Ansichten (letzte 30 Tage)
Juan Pablo Restrepo Uribe
Juan Pablo Restrepo Uribe am 14 Feb. 2019
Bearbeitet: Stephen23 am 20 Dez. 2024
Hello.
In matlab it is possible to read the extension .npy, or in its absence the extension .LVM of Labview.

Akzeptierte Antwort

Andrew Knyazev
Andrew Knyazev am 11 Jun. 2019
Bearbeitet: Walter Roberson am 20 Dez. 2024
  5 Kommentare
Maria Jose Palancares Sosa
Maria Jose Palancares Sosa am 14 Jul. 2021
Super useful, thanks!
Svetlana Piner
Svetlana Piner am 18 Mär. 2022
Best response from my point of view!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (3)

Toon Weyens
Toon Weyens am 16 Feb. 2021
If you have access to Python, the easiest thing would be to create a Python script such as the one below, and run that. It will find all .npz files in the current directory and convert that to .mat.
from scipy.io import savemat
import numpy as np
import glob
import os
npzFiles = glob.glob("*.npz")
for f in npzFiles:
fm = os.path.splitext(f)[0]+'.mat'
d = np.load(f)
savemat(fm, d)
print('generated ', fm, 'from', f)
  7 Kommentare
Mehrdad
Mehrdad am 5 Jul. 2024
thank you
Stephen23
Stephen23 am 20 Dez. 2024
"the easiest thing would be to create a Python script such as the one below, and run that."
This is easier:

Melden Sie sich an, um zu kommentieren.


Grace Kepler
Grace Kepler am 7 Nov. 2023
Bearbeitet: Stephen23 am 20 Dez. 2024
Yes, use code like this.
x = py.numpy.load('data.npy')
  3 Kommentare
MathWorks Supported Compilers Team
Hi Mike,
Did you try it? This works for me. Note that "py." is prepended to the normal Python command "numpy.load('data.npy')".
>> x=py.numpy.load('data.npy')
x =
Python ndarray:
1 2 3
4 5 6
7 8 9
Stephen23
Stephen23 am 20 Dez. 2024
"No. That'd be how to do it with python, not in MATLAB."
No, that is how to do it from MATLAB, not from Python:

Melden Sie sich an, um zu kommentieren.


Cam Salzberger
Cam Salzberger am 14 Feb. 2019
Hello Juan,
I don't believe that either of those file formats are natively supported in MATLAB, but you can always check File Exchange to see if anyone has written an importer for them. A quick search did not turn up anything for NPY, but LVM turned up this one. If you have any questions about that File Exchange package, it's best to direct them to the author of the package.
-Cam
  2 Kommentare
Johann Martinez
Johann Martinez am 23 Feb. 2022
One more reason to stop using Matlab. Python indeed has libraries to make use Matlab.
Stephen23
Stephen23 am 20 Dez. 2024
Bearbeitet: Stephen23 am 20 Dez. 2024

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Call MATLAB from Python finden Sie in Help Center und File Exchange

Produkte


Version

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by