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
🌐
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.
Discussions

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
Pillow to NumPy without copying data
I hoped that the some mechanism could be used to share the memory between PIL and numpy. For my purposes, a solution that would work for RGBA 8-bit images would be good enough, but a generic solution is welcome, I've stumbled upon this a couple of time already. More on github.com
🌐 github.com
13
September 13, 2019
[np and PIL] how do you load images as array and then reshape back to view the image
Image.fromarray takes an array of type np.uint8 so you can either initialize your array as np.uint8 or convert the final image to np.uint8 arr = np.zeros((20, 5000), np.uint8) Image.fromarray(np.uint8(arr[0].reshape((50, 100)), "L") More on reddit.com
🌐 r/learnpython
3
0
September 11, 2022
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
🌐
Pillow Documentation
pillow.readthedocs.io › en › stable › reference › Image.html
Image module - Pillow (PIL Fork) 12.3.0 documentation
In the case of NumPy, be aware that Pillow modes do not always correspond to NumPy dtypes. Pillow modes only offer 1-bit pixels, 8-bit pixels, 32-bit signed integer pixels, and 32-bit floating point pixels.
🌐
GeeksforGeeks
geeksforgeeks.org › python › convert-a-numpy-array-to-an-image
Convert a NumPy array to an image - GeeksforGeeks
July 15, 2025 - Once the array is converted, you can display the image or save it for later. Pillow (PIL) is a powerful image processing library that can easily convert a NumPy array into an image.
🌐
Pythoninformer
pythoninformer.com › python-libraries › numpy › numpy-and-images
PythonInformer - Image processing with pillow and NumPy
October 2, 2022 - By Martin McBride, 2022-10-02 Tags: image processing rgb transparency pil pillow Categories: numpy pillow · In this section, we will learn how to use NumPy to store and manipulate image data.
🌐
Reddit
reddit.com › r/learnpython › converting between pil image and 2d pixel array?
r/learnpython on Reddit: Converting between PIL Image and 2d pixel array?
May 11, 2022 -

I need to do the following:

  1. Import an image.

  2. Convert image to a 2D array of pixel values (rgb tuples, bytes, whatever it doesn't matter).

  3. Manipulate that 2D array (needs to be 2D as I'm using a library that requires a 2D array of data).

  4. Convert the newly changed 2D array back into an image.

  5. Save the image.

Anyone know how I can accomplish this? PIL Image documentation has some functions to get data but it's all 1D arrays, and I'm not sure how to get them into 2D arrays and then re-convert it back into an image again.

Find elsewhere
🌐
DEV Community
dev.to › hyperkai › conversion-with-pil-image-pytorch-tensor-numpy-array-152c
Conversion with PIL image, PyTorch tensor & NumPy array - DEV Community
May 14, 2025 - PIL image[H, W, C] => NumPy array[H, W, C] => PyTorch tensor[C, H, W] => PIL image[H, W, C]: from torchvision.datasets import OxfordIIITPet from torchvision.transforms.v2 import ToPILImage import numpy as np import torch origin_data = OxfordIIITPet( ...
🌐
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).
🌐
Roboflow
roboflow.com › use opencv › convert pil image to numpy array
Convert PIL Image to NumPy array (OpenCV)
HOW TO GUIDE · 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.
🌐
DataCamp
datacamp.com › doc › numpy › converting-images-to-numpy
Converting Images to NumPy
Images are often converted to NumPy arrays to leverage efficient numerical computation, which is beneficial for tasks like machine learning and data analysis. from PIL import Image import numpy as np image = Image.open('path_to_image.jpg') image_array = np.array(image)
🌐
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.
🌐
GitHub
github.com › python-pillow › Pillow › issues › 4064
Pillow to NumPy without copying data · Issue #4064 · python-pillow/Pillow
September 13, 2019 - meaning both PIL and numpy allocate memory (~35 and ~50 mb respectively). I've also tried using np.array (somehow takes 80 mb instead of 50 mb) instead of np.asarray, specifying the dtype for the numpy arrays (uint8, int32 (one long per pixel)), to no avail.
Author   python-pillow
🌐
PyPI
pypi.org › project › pillow
pillow · PyPI
Pillow is the friendly PIL fork by Jeffrey 'Alex' Clark and contributors. PIL is the Python Imaging Library by Fredrik Lundh and contributors. Development is supported by: ... The Python Imaging Library adds image processing capabilities to your Python interpreter.
      » pip install pillow
    
Published   Jul 01, 2026
Version   12.3.0
🌐
Univ-lille
icare.univ-lille.fr › how-to-convert-a-matplotlib-figure-to-a-numpy-array-or-a-pil-image
How to convert a matplotlib figure to a numpy array or a PIL image – ICARE Data and Services Center
import Image def fig2img ( fig ): """ @brief Convert a Matplotlib figure to a PIL Image in RGBA format and return it @param fig a matplotlib figure @return a Python Imaging Library ( PIL ) image """ # put the figure pixmap into a numpy array buf = fig2data ( fig ) w, h, d = buf.shape return ...
🌐
Pluralsight
pluralsight.com › blog › tech guides & tutorials
Importing Image Data Into NumPy Arrays | Pluralsight
April 15, 2025 - In Python, Pillow is the most popular and standard library when it comes to working with image data. NumPy uses the asarray() class to convert PIL images into NumPy arrays. The np.array function also produce the same result.
🌐
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 - Now you understand why we need the tobytes() method here: it transforms the internal representation of a Pillow image into a continuous flow of bytes without omissions, and that’s exactly what NumPy can use.
🌐
Medium
medium.com › @whyamit101 › step-by-step-guide-to-convert-numpy-array-to-pil-image-f7f8492cd785
Step-by-Step Guide to Convert NumPy Array to PIL Image | by why amit | Medium
February 9, 2025 - Grayscale images are simpler to handle, with just one channel. You created a grayscale NumPy array and converted it to a PIL image using the 'L' mode.
🌐
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 - Here’s an example: ... 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)
🌐
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 - In the realm of image processing, the Python Imaging Library (PIL) and NumPy are two indispensable tools. This blog post will guide you through the process of converting an RGB PIL image to a NumPy array with 3 channels. This conversion is a common task in image processing, machine learning, and computer vision applications.