我有一个形状数组(7,4,100,100),这意味着7个尺寸为100x100且深度为4的图像。我想在一个图上显示所有这些图像。我尝试使用matplotlib:
input_arr=numpy.load(r'C:\Users\x\samples.npy')
for i, el in enumerate(input_arr):
#moving axis to use plt: i.e [4,100,100] to [100,100,4]
array2= numpy.moveaxis(input_arr[i],0,-1)
plt.subplot(3,3, i + 1), plt.imshow(array2[i])
plt.show()
答案 0 :(得分:1)
当您使用np.moveaxis
移动轴时,您已经将输入数组编入索引以仅获取数组的 i-th 组件。因此,当您使用imshow
时,您不需要绘制array2
的 i-th 索引,而是整个array2
。
for i, el in enumerate(input_arr):
#moving axis to use plt: i.e [4,100,100] to [100,100,4]
array2 = numpy.moveaxis(input_arr[i], 0, -1)
plt.subplot(3, 3, i + 1)
plt.imshow(array2) # <- I changed this line
plt.show()
您可以通过打印array2
和array2[i]
print array2.shape
# (100, 100, 4)
print array2[i].shape
# (100, 4)