Python 使用数组列表作为索引,在数组中迭代以绘制数据集中的20个图像时出现问题
我正在尝试使用Python 使用数组列表作为索引,在数组中迭代以绘制数据集中的20个图像时出现问题,python,loops,matplotlib,plot,Python,Loops,Matplotlib,Plot,我正在尝试使用plt.imshow(xtrain[rand20[I]])从xtrain中绘制图像,理想情况下,我会迭代数组rand20 我还需要创建一个5x4子地块 rand20 = array([ 80, 337, 275, 651, 226, 681, 282, 958, 150, 790, 954, 929, 846, 848, 177, 165, 280, 196, 694, 159])
plt.imshow(xtrain[rand20[I]])
从xtrain中绘制图像,理想情况下,我会迭代数组rand20
我还需要创建一个5x4子地块
rand20 = array([ 80, 337, 275, 651, 226,
681, 282, 958, 150, 790,
954, 929, 846, 848, 177,
165, 280, 196, 694, 159])
我被困在这里,任何帮助都将不胜感激 您可以在此处使用
zip
:
plt.subplot(5,4,1)
plt.imshow(xtrain[rand20[0]])
fig, axes = plt.subplots(5,4,1)
for idx, ax in zip(rand20, axes.ravel()):
ax.imshow(xtrain[idx])