简体   繁体   中英

How to convert a python list of 3D arrays to a single 3D array of specific shape?

I have a list itemlist that has 25 3D Arrays with shape (128x128x3)

I want it to convert/merge all these values into a single common array, basically create a image out of it. I'm expecting the new shape to be (640, 640, 3) meaning 5 rows and 5 columns of (128, 128)

I tried the following, but it is giving weird results, mostly repeating some arrays:

out = np.concatenate(itemlist).ravel()
out.shape ##(1228800,)

img = np.reshape(out, (640,640,3))
img.shape ## (640, 640, 3) 

The final shape I get is correct but visually it looks like set of repeated images, is something wrong with logic?

With 25 (128,128,3) arrays

out = np.concatenate(itemlist)

should produce a (25*128, 128,3) array

out = out.ravel()

should produce 25 128 128*3

out.shape ##(1228800,)

(640,640,3) matches in total number of elements, but it will not produce meaningful images.

Working backwards:

(5*128, 5*128,3)  => (5,128,5,128,3) => (5,5,128,128,3) => (25,128,128,3)

That requires a couple of reshapes, and one tranpose.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM