Your array of "binary values" is an array of bytes?

If so, you can do (using Pillow) after resizing it:

from PIL import Image
im = Image.fromarray(arr)

And then im.show() to see it.

If your array has only 0's and 1's (1-bit depth or b/w) you may have to multiply it to 255

im = Image.fromarray(arr * 255)

Here an example:

>>> arr = numpy.random.randint(0,256, 100*100) #example of a 1-D array
>>> arr.resize((100,100))
>>> im = Image.fromarray(arr)
>>> im.show()

Edit (2018):

This question was written in 2011 and Pillow changed ever since requiring to use the mode='L' parameter when loading with fromarray.

Also on comments below it was said arr.astype(np.uint8) was needed as well, but I have not tested it

Answer from JBernardo on Stack Overflow
Discussions

Python: Converting a numpy matrix to a grayscale image - Stack Overflow
I want to convert a numpy matrix with positive and negative values of type np.float to a grayscale image with pixels from [0,255]. I want to do that as fast as possible. Right now I am doing the More on stackoverflow.com
🌐 stackoverflow.com
How to convert grayscale values in matrix to an image in Python? - Stack Overflow
I have a set of grayscale values in matrix of shape 24x24: masked=[[149 172 160 166 170 179 180 176 202 190 221 232 125 112 153 132 200 185 191 231 227 101 85 127] ... And I try to save this ma... More on stackoverflow.com
🌐 stackoverflow.com
Converting an RGB image to grayscale and manipulating the pixel data in python - Stack Overflow
I have an RGB image which I want to convert to a grayscale image, so that I can have one number (maybe between 0 and 1) for each pixel. This gives me a matrix which has the dimensions equal to that... More on stackoverflow.com
🌐 stackoverflow.com
March 11, 2016
python - Converting an image to grayscale using numpy - Stack Overflow
I have an image represented by a numpy.array matrix nxm of triples (r,g,b) and I want to convert it into grayscale, , using my own function. My attempts fail converting the matrix nxmx3 to a matri... More on stackoverflow.com
🌐 stackoverflow.com
July 11, 2018
🌐
TutorialsPoint
tutorialspoint.com › article › how-to-save-an-array-as-a-grayscale-image-with-matplotlib-numpy
How to save an array as a grayscale image with Matplotlib/Numpy?
import numpy as np import matplotlib.pyplot as plt # Set figure size plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True # Create random data with 5x5 dimension arr = np.random.rand(5, 5) # Display as grayscale image plt.imshow(arr, cmap='gray') plt.colorbar() # Add colorbar to show intensity scale plt.title('Grayscale Image from Array') # Save the image plt.savefig('/images/grayscale_output.png', dpi=300, bbox_inches='tight') plt.show()
Find elsewhere
🌐
Quora
quora.com › How-do-I-turn-NumPY-arrays-into-grayscale-images
How to turn NumPY arrays into grayscale images - Quora
Answer (1 of 3): There are several available libraries and examples of using them. They are easily found. Seek and ye shall find. [code]from PIL import Image import matplotlib.pyplot as plt import imageio [/code]You don’t use all three, but you can choose among them.
🌐
Cvut
people.ciirc.cvut.cz › ~xmatousm › mfftdv › lab1.html
Reading image as matrix, accessing individual pixels
Convert to gray-scale. Note the [:,:,?] numpy indexing that produces sub-matrix of the 3D array. ... img_gray = img[:,:,0] * 0.2989 + img[:,:,1] * 0.5870 + img[:,:,2] * 0.1140 # result is 2D array (matrix) Show the gray-scale image with the default colormap and with the grayscale one.
🌐
Saturn Cloud
saturncloud.io › blog › how-to-convert-an-image-to-grayscale-using-numpy-arrays-a-comprehensive-guide
How to Convert an Image to Grayscale Using NumPy Arrays: A Guide | Saturn Cloud Blog
May 1, 2026 - One common task is converting color images to grayscale, which can simplify subsequent analyses. Today, we’ll explore how to accomplish this using NumPy arrays. ... NumPy, short for Numerical Python, is a powerful library that supports large, multi-dimensional arrays and matrices, along with a collection of mathematical functions to operate on these arrays.
🌐
Stack Overflow
stackoverflow.com › questions › 53486396 › creating-a-greyscale-image-with-a-matrix-in-python
Creating a greyscale image with a Matrix in python - Stack Overflow
How to convert grayscale values in matrix to an image in Python? 3 · Converting jpg to greyscale · 0 · Convert an image to grayscale using only matrix (No BGR2GRAY function) in Python · 1 · Converting image to greyscale outputs wrong result · 2 · Python: Converting a numpy matrix to a grayscale image ·
🌐
scikit-image
scikit-image.org › skimage-tutorials › lectures › 00_images_are_arrays.html
Images are numpy arrays — Image analysis in Python
Use Python 3.5’s matrix multiplication, @, to convert an RGB image to a grayscale luminance image according to the formula above.
🌐
Stack Overflow
stackoverflow.com › questions › 66518986 › converting-image-to-grayscale-python
numpy - Converting image to grayscale python - Stack Overflow
September 26, 2021 - 2 How to change an image to grayscale represented as a NumPy array · 2 Python: Converting a numpy matrix to a grayscale image · 2 Grayscale .png to numpy array · 0 how do i convert image into gray scale using python? 3 Converting multiple numpy images to gray scale ·
🌐
Finxter
blog.finxter.com › home › learn python blog › 5 best ways to convert a python numpy array to a grayscale image
5 Best Ways to Convert a Python NumPy Array to a Grayscale Image - Be on the Right Side of Change
February 20, 2024 - This code snippet creates a random 2D array of floating-point numbers, converts the array to 8-bit unsigned integers, and uses matplotlib to display it as a grayscale image. The axes are removed for a cleaner look, and then the image is saved as a PNG file without any padding around the edges. The Python Imaging Library (PIL), known as Pillow in its current form, provides the Image module that can convert NumPy arrays to image objects.
🌐
Stack Overflow
stackoverflow.com › questions › 40768219 › how-to-convert-an-image-which-is-given-as-matrix-representation-to-grayscale-ima
rgb - how to convert an image which is given as matrix representation to grayscale image? - Stack Overflow
consider the an image as [ 1 2 3; 4 5 6 ; 7 8 9] matrix. How we can convert given image to grayscale image. I know that we need to get r,g,b values of each pixel. And using 0.2*R+0.7*G+0.1*B formu...
🌐
Fast.ai
forums.fast.ai › part 1 (2018)
Convert colour to grey scale numpy array - Part 1 (2018) - fast.ai Course Forums
October 13, 2018 - How do I convert an array of two colour images to an array of two gray scale images using the to_grayscale (from this site) function below. Important: I don’t want image files, I want the array image_g defined below.