How do read .npy files in matlab?
Afficher commentaires plus anciens
Hello.
In matlab it is possible to read the extension .npy, or in its absence the extension .LVM of Labview.
1 commentaire
Stephen23
le 20 Déc 2024
"In matlab it is possible to read the extension .npy..."
Réponse acceptée
Plus de réponses (3)
Toon Weyens
le 16 Fév 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 commentaires
Sandra Chimeumanu Meshack
le 12 Août 2021
i tried this, it seems to work but it's asking me to allow_pickle=True
Leonardo da Silva Costa
le 13 Déc 2021
Modifié(e) : Leonardo da Silva Costa
le 13 Déc 2021
In my case I had to do something like this
X = np.load('./dataset/dataset_Xs.npy')
savemat('./dataset/dataset_Xs.mat', {'X': X})
Varun Vasudevan
le 7 Mar 2022
Modifié(e) : Varun Vasudevan
le 7 Mar 2022
This works. Thanks Leonardo :)
Grzegorz Klosowski
le 8 Sep 2022
Good job. Thanks.
Mark Sie
le 18 Juin 2023
Help me greatly thank u
Mehrdad
le 5 Juil 2024
thank you
Stephen23
le 20 Déc 2024
"the easiest thing would be to create a Python script such as the one below, and run that."
This is easier:
Grace Kepler
le 7 Nov 2023
Modifié(e) : Stephen23
le 20 Déc 2024
Yes, use code like this.
x = py.numpy.load('data.npy')
3 commentaires
Mike Jonson
le 10 Sep 2024
Modifié(e) : Mike Jonson
le 10 Sep 2024
No. That'd be how to do it with python, not in MATLAB.
MathWorks Supported Compilers Team
le 11 Sep 2024
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
le 20 Déc 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:
Cam Salzberger
le 14 Fév 2019
1 vote
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 commentaires
Johann Martinez
le 23 Fév 2022
One more reason to stop using Matlab. Python indeed has libraries to make use Matlab.
"Python indeed has libraries to make use Matlab."
MATLAB indeed has functions to make use Python:
Catégories
En savoir plus sur Call MATLAB from Python dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!