How to convert Matlab cell array into Python numpy array?
古いコメントを表示
In matlab, I generate a random # of images of the shape (130,100) and save them one by one in a cell array. I then need to import this cell array of images into python and convert them into a numpy array (number_images, 130,100).
I've tried the following, but I get an error. Not sure how to fix. Would appreciate help- thanks!
import scipy.io as sio
import numpy
from PIL import Image
folder='insert path of mat file here'
imgs = sio.loadmat(folder+'/img_array.mat')
num_imgs=len(imgs['img_array'][0])
img_array=np.array(imgs['img_array'][0])
new_array=img_array.reshape((num_images,130,100))
ValueError: cannot reshape array of size 9 into shape (9,130,100)
**In this case, 9 images were generated from matlab, and this was the cell array shown.

採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Call Python from MATLAB についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!