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 - 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
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
Converting between PIL Image and 2d pixel array?
functions to get data but it's all 1D arrays, You might mean the getdata() method which returns a sequence object which contains the image data. You can use that to create 2D data. You get the image row length from the Image.size attribute , read one row length of pixel data from the sequence and store it as one row in your 2D data. More on reddit.com
🌐 r/learnpython
5
3
May 11, 2022
Numpy array won't convert PIL Image
Did you redefine np.array somewhere? Like did you do np.array = int or something? More on reddit.com
🌐 r/learnpython
2
2
June 20, 2019
🌐
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
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.
🌐
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 › blog › how to convert pil images to numpy array
How To Convert PIL Images to Numpy Array - Python Pool
September 10, 2022 - For example, let’s say you’re receiving a base64 encoded image from HTTP. How do we convert to a Numpy Array? ... import torch import numpy as np from PIL import Image import base64 base64_decoded = base64.b64decode(test_image_base64_encoded) with open("sample.jpg", "wb") as sample: sample.write(base64_decoded) image = Image.open("sample.jpg") imageArray = np.array(image)
🌐
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.
Find elsewhere
🌐
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
February 8, 2024 - 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.
🌐
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....
🌐
Pluralsight
pluralsight.com › tech insights & how-to guides › tech guides & tutorials
Importing Image Data Into NumPy Arrays | Pluralsight
April 15, 2025 - For example, the code below loads the photograph in JPEG format and saves it in PNG format. import numpy as np from PIL import Image im = np.array(Image.open('kolala.jpeg').convert('L')) #you can pass multiple arguments in single line ...
🌐
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.
🌐
Pythoninformer
pythoninformer.com › python-libraries › numpy › numpy-and-images
PythonInformer - Image processing with pillow and NumPy
October 2, 2022 - The transparency varies smoothly from left to right: import numpy as np from PIL import Image array = np.zeros([100, 200, 4], dtype=np.uint8) array[:,:100] = [255, 128, 0, 255] #Orange left side array[:,100:] = [0, 0, 255, 255] #Blue right side # Set transparency based on x position array[:, ...
🌐
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)
🌐
Clementine Blog
clementine.hashnode.dev › how-to-read-image-from-path-and-convert-to-a-numpy-array-in-python
How to read Image from Path and Convert to a NumPy Array in Python.
March 11, 2021 - from PIL import Image img = Image.open(image_path) img = np.array(img) The result below: #numpy#python#opencv
🌐
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)
🌐
Note.nkmk.me
note.nkmk.me › home › python › numpy
Image processing with Python, NumPy | note.nkmk.me
October 20, 2020 - Passing the image data read by PIL.Image.open() to np.array() returns 3D ndarray whose shape is (row (height), column (width), color (channel)). from PIL import Image import numpy as np im = np.array(Image.open('data/src/lena.jpg')) print(type(im)) ...