Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/345.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 如何修复保存多个图像的代码?_Python_Python 3.x - Fatal编程技术网

Python 如何修复保存多个图像的代码?

Python 如何修复保存多个图像的代码?,python,python-3.x,Python,Python 3.x,我正在研究用Python 3保存多个图像的编码问题。我需要立即完成所有21张图片的保存 我不知道如何写下正确的代码 image_new = ... img_dir = 'C:\Users\...' for i in image_new: j = np.array(i) … j = Image.fromarray(j.astype(np.uint8)) j.save(os.path.join(img_dir, "image1-21.jpg")) #

我正在研究用Python 3保存多个图像的编码问题。我需要立即完成所有21张图片的保存

我不知道如何写下正确的代码

image_new = ... 
img_dir = 'C:\Users\...' 
for i in image_new:
     j = np.array(i) 
     … 
     j = Image.fromarray(j.astype(np.uint8)) 
     j.save(os.path.join(img_dir, "image1-21.jpg")) #this line has to be fixed 


我只能使用file.save(os.path.join(image#dir,“image#.jpg”))将最后一张图像21保存到目标文件夹中。

假设
image#u new
包含所有21张图像,并且它们可以按顺序区分:

image_new = ... 
img_dir = 'C:\Users\...' 
for num, i in enumerate(image_new):
     j = np.array(i) 
     … 
     j = Image.fromarray(j.astype(np.uint8)) 
     j.save(os.path.join(img_dir, "image-{}.jpg".format(num + 1)))

使用
enumerate()?我的意思是它是一个数字还是别的什么?我代表一个矩阵。感谢你们的经济!你帮了我的忙!!再次感谢你!很乐意帮忙。请接受答案,让其他人知道它有效。