简体   繁体   English

如何将 3D arrays 的 python 列表转换为特定形状的单个 3D 数组?

[英]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)我有一个列表项列表,其中包含 25 个itemlist 3D Arrays形状(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)我期待新的形状是(640, 640, 3)意思是5 rows and 5 columns (128, 128)

I tried the following, but it is giving weird results, mostly repeating some arrays:我尝试了以下方法,但结果很奇怪,主要是重复一些 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与 25 (128,128,3) arrays

out = np.concatenate(itemlist)

should produce a (25*128, 128,3) array应该产生一个 (25*128, 128,3) 数组

out = out.ravel()

should produce 25 128 128*3应该产生 25 128 128*3

out.shape ##(1228800,)

(640,640,3) matches in total number of elements, but it will not produce meaningful images. (640,640,3)匹配元素总数,但不会产生有意义的图像。

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.这需要几次重塑和一次转置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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