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 โ€บ convert-a-numpy-array-to-an-image
Convert a NumPy array to an image - GeeksforGeeks
July 15, 2025 - The Image.fromarray() function is used for this task, which takes a NumPy array as input and creates a PIL Image object.
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 - How to read image from numpy array into PIL Image? - Stack Overflow
I am trying to read an image from a numpy array using PIL, by doing the following: from PIL import Image import numpy as np #img is a np array with shape (3,256,256) Image.fromarray(img) and am ge... More on stackoverflow.com
๐ŸŒ stackoverflow.com
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
[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
๐ŸŒ
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 - Run this code, and boom โ€” youโ€™ve got your image data ready in array form! ... Here comes the exciting part: transforming your NumPy array into an actual image! Weโ€™ll use Image.fromarray() from the PIL library.
๐ŸŒ
GitHub
gist.github.com โ€บ e5048001b4ff89b6a7e1aec4b5bb41f1
How to convert between NumPy array and PIL Image ยท GitHub
How to convert between NumPy array and PIL Image. GitHub Gist: instantly share code, notes, and snippets.
๐ŸŒ
Pythoninformer
pythoninformer.com โ€บ python-libraries โ€บ numpy โ€บ numpy-and-images
PythonInformer - Image processing with pillow and NumPy
October 2, 2022 - Now let's fill the array with orange pixels (red=255, green=128, blue=0). We use slices to do this, the three values are broadcast across all the rows and columns of the array: ... The PIL function Image.fromarray function creates a PIL image from a NumPy array.
๐ŸŒ
Delft Stack
delftstack.com โ€บ home โ€บ howto โ€บ matplotlib โ€บ convert a numpy array to pil image python
How to Convert a NumPy Array to PIL Image in Python | Delft Stack
February 2, 2024 - Here, we create a NumPy array of size 400x400 with random numbers ranging from 0 to 255 and then convert the array to an Image object using the Image.fromarray() function and display the image using show() method. import numpy as np from PIL import ...
Find elsewhere
๐ŸŒ
GitHub
github.com โ€บ mthiboust โ€บ array2image
GitHub - mthiboust/array2image: Converts a Numpy array to a PIL image. ยท GitHub
November 22, 2023 - def array_to_image( arr, spatial_dims: tuple[int, ...] | None = None, channel_dim: int | None = None, cmap: Callable | None = None, inverted_colors: bool = False, bin_size: int | tuple[int, int] | None = None, target_total_size: int = 200, grid_thickness: int | tuple[int, ...] = 0, norm: bool = False, ) -> PIL.Image
Author ย  mthiboust
๐ŸŒ
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.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ how-to-convert-images-to-numpy-array
How to Convert images to NumPy array? - GeeksforGeeks
July 15, 2025 - To work with them in Python, we ... using a NumPy array is a table of numbers showing each pixelโ€™s color. In this article, weโ€™ll learn how to do this using popular Python tools. Let us check for an image that is in the PNG or JPEG format. The image can be referred via its path. Image class is the heart of PIL...
๐ŸŒ
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.
๐ŸŒ
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 - My post explains device conversion with to(), from_numpy() and numpy(). My post explains permute(). My post explains OxfordIIITPet(). You can do conversion with PIL(Pillow library) Image, PyTorch tensor and NumPy array as shown below: from torchvision.datasets import OxfordIIITPet origin_data = OxfordIIITPet( root="data", transform=None ) import matplotlib.pyplot as plt plt.figure(figsize=[7, 9]) plt.title(label="s500_394origin_data", fontsize=14) plt.imshow(X=origin_data[0][0]) plt.show() PIL image[H, W, C] => PyTorch tensor[C, H, W] => NumPy array[H, W, C] => PIL image[H, W, C]: from torchvi
๐ŸŒ
w3resource
w3resource.com โ€บ python-exercises โ€บ numpy โ€บ python-numpy-exercise-109.php
Python NumPy: Convert a numpy array to an image - w3resource
August 29, 2025 - img = Image.fromarray(data, 'RGB'): Convert the NumPy array 'data' to a PIL Image object with the mode 'RGB' (red, green, blue).
๐ŸŒ
Pillow Documentation
pillow.readthedocs.io โ€บ en โ€บ stable โ€บ releasenotes โ€บ 8.3.1.html
8.3.1 (2021-07-06) - Pillow (PIL Fork) 12.1.1 documentation
July 6, 2021 - This fixes a regression introduced in 8.3.0 when converting an image to a NumPy array with a dtype argument. >>> from PIL import Image >>> import numpy >>> im = Image.new("RGB", (100, 100)) >>> numpy.array(im, dtype=numpy.float64) Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: __array__() takes 1 positional argument but 2 were given >>> In 8.3.0, a check to see if the destination was sys.stdout when saving an image was updated.
๐ŸŒ
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 numpy def fig2data ( fig ): """ @brief Convert a Matplotlib figure to a 4D numpy array with RGBA channels and return it @param fig a matplotlib figure @return a numpy 3D array of RGBA values """ # draw the renderer fig.canvas.draw ( ) # Get the RGBA buffer from the figure w,h = fig.canvas.get_width_height() buf = numpy.fromstring ( fig.canvas.tostring_argb(), dtype=numpy.uint8 ) buf.shape = ( w, h,4 ) # canvas.tostring_argb give pixmap in ARGB mode. Roll the ALPHA channel to have it in RGBA mode buf = numpy.roll ( buf, 3, axis = 2 ) return buf Conversion to a PIL image At this point, we just have to convert the numpy array to a PIL Image to end the conversion.
๐ŸŒ
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 ...
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ python_pillow โ€บ python_pillow_m_l_with_numpy.htm
Python Pillow - M L with Numpy
The mode is either explicitly specified or inferred from the dtype of the input array. In this example, a NumPy array is created, and then Image.fromarray() is used to create a Pillow Image from the NumPy array.
๐ŸŒ
Python Examples
pythonexamples.org โ€บ python-pillow-convert-numpy-array-to-image
Python Pillow โ€“ Convert Numpy Array to Image
To convert a given NumPy array to an image using Pillow library in Python, call Image.fromarray() function and pass the given NumPy array as argument. The function returns a PIL Image object. You can then save this Image object as an image file in the disk storage.