import PIL.image def save_image(arr, fp, format='JPEG'): image = PIL.Image.fromarray(arr) image.save(fp, format=format, quality=90) def save_images(ims, path_prefix='', format='JPEG'): for i, im in enumerate(ims): path = str(path_prefix)+str(i).zfill(4)+'.'+str(format).lower() save_image(im, path)