Numpy 3d arrays to matlab

40 Ansichten (letzte 30 Tage)
Rémi Grisot
Rémi Grisot am 30 Jun. 2020
Kommentiert: Rémi Grisot am 6 Jul. 2020
Hi,
I have a dataset made of 3d arrays in numpy. I want to use this dataset in Matlab. I can write these 3d arrays to csv but they are written as string. I know how to deserialize them in python but not in Matlab. Is there a way to do so? Maybe using csv as an intermediate is not the best choice. Is there anything better you would recommend ?
Here is the code I use in Python for deserialization :
x_array = inputs.apply(lambda x:
np.fromstring(
x.replace('\n','')
.replace('[','')
.replace(']','')
.replace(' ',' '), sep=' ')
.reshape(20,20)).apply(lambda x:
np.array([x]))
Thank you!

Akzeptierte Antwort

SC
SC am 30 Jun. 2020
  1 Kommentar
Rémi Grisot
Rémi Grisot am 6 Jul. 2020
Thank you for the links, it helped me for some parts of the solutions. Here is what I produced :
import scipy.io
arr_train = np.stack(data['hist'].values)
scipy.io.savemat('data/data.mat', mdict={'train': arr_train})
arr_valid = np.stack(data_valid['hist'].values)
scipy.io.savemat('data/data_valid.mat', mdict={'test': arr_valid})

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Manage Products finden Sie in Help Center und File Exchange

Produkte


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by