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!