You're not saying how exactly putdata() is not behaving. I'm assuming you're doing

>>> pic.putdata(a)
Traceback (most recent call last):
  File "...blablabla.../PIL/Image.py", line 1185, in putdata
    self.im.putdata(data, scale, offset)
SystemError: new style getargs format but argument is not a tuple

This is because putdata expects a sequence of tuples and you're giving it a numpy array. This

>>> data = list(tuple(pixel) for pixel in pix)
>>> pic.putdata(data)

will work but it is very slow.

As of PIL 1.1.6, the "proper" way to convert between images and numpy arrays is simply

>>> pix = numpy.array(pic)

although the resulting array is in a different format than yours (3-d array or rows/columns/rgb in this case).

Then, after you make your changes to the array, you should be able to do either pic.putdata(pix) or create a new image with Image.fromarray(pix).

Answer from dF. on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › python › how-to-convert-images-to-numpy-array
How to Convert images to NumPy array? - GeeksforGeeks
July 15, 2025 - Explanation: It converts a PIL image to a NumPy array using img_to_array() for processing, then back to a PIL image using array_to_img(), confirming smooth transformation with array type float32 and shape (200, 400, 3).
Discussions

Python PIL image list to numpy array help
Got it to work, so for future people(Hello!): def getImages(path) : paths = [] images = [] valid_images = [".jpg",".gif",".png",".tga"] for f in os.listdir(path): ext = os.path.splitext(f)[1] if ext.lower() not in valid_images: continue paths.append(os.path.join(path,f)) paths.sort() #make sure every image is sorted correctly for p in paths : images.append(np.asarray(Image.open(os.path.join(p)))) return np.asanyarray(images) More on reddit.com
🌐 r/CodingHelp
4
3
October 26, 2021
python - How to convert a NumPy array to PIL image applying matplotlib colormap - Stack Overflow
I want to take a NumPy 2D array which represents a grayscale image, and convert it to an RGB PIL image while applying some of the matplotlib colormaps. I can get a reasonable PNG output by using the More on stackoverflow.com
🌐 stackoverflow.com
Pillow to NumPy without copying data
I'm trying to see if there is a way to go from a Pillow image to a numpy array without duplicating the data. More on github.com
🌐 github.com
September 13, 2019
Converting between PIL Image and 2d pixel array?
Are you trying to translate a image into ascii art? More on reddit.com
🌐 r/learnpython
5
3
May 11, 2022
People also ask

How do I convert a NumPy array back to a PIL image?
Use Image.fromarray(array) after ensuring the array dtype, shape, and value range match the desired Pillow mode.
🌐
pythonpool.com
pythonpool.com › home › numpy › convert a pil image to a numpy array: modes, shape, and dtype
Convert a PIL Image to a NumPy Array: Modes, Shape, and Dtype
What is the difference between np.asarray() and np.array()?
asarray() avoids a copy when possible, while np.array() generally creates a new array unless copy behavior is changed explicitly.
🌐
pythonpool.com
pythonpool.com › home › numpy › convert a pil image to a numpy array: modes, shape, and dtype
Convert a PIL Image to a NumPy Array: Modes, Shape, and Dtype
What shape does an RGB image have?
An RGB image commonly has shape (height, width, 3), while RGBA has a fourth channel for alpha.
🌐
pythonpool.com
pythonpool.com › home › numpy › convert a pil image to a numpy array: modes, shape, and dtype
Convert a PIL Image to a NumPy Array: Modes, Shape, and Dtype
🌐
Educative
educative.io › answers › convert-a-pil-image-to-numpy-array
Convert a PIL image to NumPy array
Line 1: We import Image module from the PIL library. Line 3: We open the image using the Image.open() function and pass the file name of the image as a parameter. Line 5: We print the image, which shows that the image is a JPEG image.
🌐
w3resource
w3resource.com › python-exercises › numpy › python-numpy-exercise-108.php
Python NumPy: Convert a PIL Image into a NumPy array - w3resource
August 29, 2025 - Create a function that transforms a PIL image into grayscale and returns the corresponding NumPy array. Test the conversion with images of different modes (RGB, L, RGBA) and compare the array dimensions.
🌐
Pluralsight
pluralsight.com › blog › tech guides & tutorials
Importing Image Data Into NumPy Arrays | Pluralsight
April 15, 2025 - The shape of the array is 800 pixels ... standard library when it comes to working with image data. NumPy uses the asarray() class to convert PIL images into NumPy arrays....
🌐
DataCamp
datacamp.com › doc › numpy › converting-images-to-numpy
Converting Images to NumPy
Always check the shape of the resulting ... usage by resizing or converting to grayscale. Use libraries. Leverage libraries like Pillow (`PIL`) for versatile image file handling and conversion to NumPy arrays....
Find elsewhere
🌐
Roboflow
roboflow.com › use opencv › convert pil image to numpy array
Convert PIL Image to NumPy array (OpenCV)
You can convert a PIL Image object into a NumPy array using the np.asarray() function: import numpy as np from PIL import Image pil_image = Image.open("image.jpeg") image = np.asarray(pil_image) OpenCV can be used with the open source supervision Python package.
🌐
Python Pool
pythonpool.com › home › numpy › convert a pil image to a numpy array: modes, shape, and dtype
Convert a PIL Image to a NumPy Array: Modes, Shape, and Dtype
July 13, 2026 - Convert Pillow images to NumPy arrays with np.asarray(), inspect RGB and RGBA modes, copy safely, and convert arrays back to images.
🌐
CodeSpeedy
codespeedy.com › home › convert pil image to numpy array in python
Convert PIL image to NumPy array in Python
November 9, 2022 - # Import all the required libraries from PIL import Image from numpy import asarray # copy the name of the sample image img = Image.open('sample.jpg') #numpy arrays is converted from PIL images using asarray()class.
🌐
Saturn Cloud
saturncloud.io › blog › how-to-convert-rgb-pil-image-to-numpy-array-with-3-channels-a-comprehensive-guide
How to Convert RGB PIL Image to Numpy Array with 3 Channels: A Guide | Saturn Cloud Blog
May 1, 2026 - The resulting img_array is a 3D NumPy array, where the first dimension represents the height, the second dimension represents the width, and the third dimension represents the RGB channels. To verify that our conversion was successful, we can print the data types. ... Versatility: The combination of PIL and NumPy provides a versatile solution for handling and manipulating images, catering to a wide range of image processing tasks.
🌐
Linux Hint
linuxhint.com › pil-image-to-numpy-array
Linux Hint – Linux Hint
November 9, 2022 - Linux Hint LLC, [email protected] 1210 Kelly Park Circle, Morgan Hill, CA 95037 Privacy Policy and Terms of Use
🌐
Delft Stack
delftstack.com › home › howto › numpy › pil image to numpy array
How to Convert PIL Image to NumPy Array | Delft Stack
March 11, 2025 - Here’s how you can do it: from PIL import Image import numpy as np # Open an image file image = Image.open('example_image.jpg') # Convert the image to a NumPy array image_array = np.array(image) print(image_array.shape)
🌐
Reddit
reddit.com › r/codinghelp › python pil image list to numpy array help
r/CodingHelp on Reddit: Python PIL image list to numpy array help
October 26, 2021 -

Heya all,

I am basically trying to get a numpy array of images as input for my neural network. But I seem to be unable to use asarray on my PIL images list

Code snippet

def getImages(path) :
    paths = []
    images = []
    #path = "/home/drBunsen/Downloads/code/yadayada/
    valid_images = [".jpg",".gif",".png",".tga"]
    for f in os.listdir(path):
        ext = os.path.splitext(f)[1]
        if ext.lower() not in valid_images:
            continue
        #imgs.append(Image.open(os.path.join(path,f)))
        paths.append(os.path.join(path,f))
    paths.sort() #make sure every image is sorted correctly
    for p in paths :
        images.append(Image.open(os.path.join(p)))
    return images

Next I get my images and want them in a numpy array

np.asarray(getImages("path"))
np.array(getImages("path"))

neihter of these work

TypeError: int() argument must be a string, a bytes-like object or a number, not 'JpegImageFile'

I can only get the following to work

np.asarray(getImages("path")[0])
np.array(getImages("path")[0])

Is there anyway to just attack the whole list?

Thanks in advance.

🌐
Edureka Community
edureka.co › home › community › categories › python › how to convert a pil image into a numpy array
How to convert a PIL Image into a numpy array | Edureka Community
June 22, 2020 - I'm trying around with converting a PIL image object back and forth to a numpy array so I can do some ... , but can't quite seem to get it to behave.
🌐
Matias Codesal
matiascodesal.com › posts › how-convert-pillow-pil-image-numpy-array-fast
How to Convert a Pillow (PIL) Image to a Numpy Array FAST!
December 22, 2020 - import numpy as np from PIL import Image img = Image.open(filepath) # datatype is optional, but can be useful for type conversion data = np.asarray(img, dtype=np.uint8)
🌐
Uploadcare
uploadcare.com › processing & transformations category › fast pillow image import to numpy and opencv arrays
Fast Pillow image import to NumPy and OpenCV arrays | Uploadcare
September 7, 2021 - Here are the two most common ways to convert a Pillow image to NumPy. If you Google it, you’ll probably find one of them: numpy.array(im) — makes a copy from an image to a NumPy array.
🌐
AskPython
askpython.com › python › examples › convert-images-to-numpy-arrays
How to Convert Images to Numpy Arrays in Python - AskPython
April 21, 2026 - Pillow is the go-to library for basic image loading in Python. Pair it with numpy.asarray() and you get an array without installing anything heavy.
🌐
GitHub
github.com › python-pillow › Pillow › issues › 4064
Pillow to NumPy without copying data · Issue #4064 · python-pillow/Pillow
September 13, 2019 - For posterity: I've tried doing the same thing with imageio, and while it does indeed convert to a numpy array without overhead once loaded, it internally uses Pillow (it literally calls frame = np.array(frame, dtype=dtype) in pillow.py:637, where frame is of type PIL.JpegImagePlugin.JpegImageFile), so the memory consumptions is even worse (instead of the above mentioned 35 mb for pure PIL to 115 mb with imageio).