[英]How to convert 4d numpy array of images to 3d?
我有 4d numpy 形狀數組(80,8,8,3)。 它是 80 張 8x8 圖像,3 個通道。 我想用它們制作一張 8 行 10 列的大圖像。 如何將 4d 數組轉換為 3d 並重塑為所需的形狀? 我嘗試np.concatenate(images[i:i + 10,:,:,:]
但由於某種原因它不起作用。
如果您只想查看它們,您可以制作 plot 而無需擺弄您的數據:
data = np.random.random((80, 8, 8, 3))
import matplotlib.pyplot as plt
fig, axs = plt.subplots(nrows=8, ncols=10, figsize=(10, 8))
for ax, img in zip(axs.ravel(), data):
ax.imshow(img)
ax.axis('off')
這導致:
如果你真的想重塑它,你可以這樣做:
n, h, w, c = data.shape
data_new = (data.reshape(8, 10, h, w, c)
.swapaxes(1,2)
.reshape(h*8, w*10, c))
到 plot 這個結果:
plt.figure(figsize=(10, 8))
plt.imshow(data_new)
plt.axis('off')
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.