Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用数组列表作为索引,在数组中迭代以绘制数据集中的20个图像时出现问题_Python_Loops_Matplotlib_Plot - Fatal编程技术网

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])