This is easily done with PIL/Pillow. Create a new grayscale image of the proper size, and convert each array value to the range 0-255 and copy it in. I added a resize at the end to make the pixels easier to see.

from PIL import Image

array1 = [[0.48, 0.4,  0.56, 0.32, 0.52],
 [0.36, 0.56, 0.56, 0.68, 0.56],
 [0.32, 0.72, 0.88, 0.44, 0.56],
 [0.56, 0.64, 0.76, 0.52, 0.48],
 [0.32, 0.88, 0.56, 0.52, 0.4 ]]

width1 = 5
height1 = 5

im = Image.new('L', (width1, height1))
pix = im.load()
for y in range(height1):
    for x in range(width1):
        pix[x, y] = int(array1[y][x] * 255.9999)

im = im.resize((width1 * 10, height1 * 10), resample=Image.NEAREST)
im.save(r'c:\temp\temp.png')

Answer from Mark Ransom on Stack Overflow
Discussions

python - Turning a Large Matrix into a Grayscale Image - Stack Overflow
As of scipy 1.0.0 this function is deprecated. You should use Image.fromarray instead. ... If you have as example a txt file in your PC with some data (an image), in order to visualize such data as gray scale image you can use this: More on stackoverflow.com
🌐 stackoverflow.com
matplotlib - Python save and read a grayscale image in two dimension array? - Stack Overflow
Communities for your favorite technologies. Explore all Collectives · Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work More on stackoverflow.com
🌐 stackoverflow.com
python - Creating a good quality grayscale image from an multidimensional numpy array - Stack Overflow
I have an array that is 50(rows) by 33(columns). I am importing it to a numpy array on python. The values on my array range from 0 to 4096, so I am scaling it to 0-255 and then I trying to create a More on stackoverflow.com
🌐 stackoverflow.com
python - How to change an image to grayscale represented as a NumPy array - Stack Overflow
Preface: I have an image of a coin. This is any generic image of a coin that I plug into python, and I want to make this coin a grayscale image. The variable P represents the array containing the ... More on stackoverflow.com
🌐 stackoverflow.com
🌐
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 ...
🌐
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()
🌐
Saskeli
saskeli.github.io › data-analysis-with-python-summer-2019 › image_processing.html
Image processing — Data analysis with Python - Summer 2019 documentation
The array contains at each coordinate pair (x,y) a value, which is typically a float between 0.0 and 1.0, or an integer between 0 and 255. This specifies the level of grayness. For example, if the array contains value 255 at coordinates (0,0), then in the image the pixel at top left is white.
🌐
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 - Color images are often represented as three-dimensional NumPy arrays, with dimensions corresponding to the height, width, and color channels of the image. Converting these to grayscale can reduce computational complexity and noise, making subsequent image processing tasks more manageable.
🌐
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.
Find elsewhere
🌐
Codecademy
codecademy.com › docs › python:pillow › image module › fromarray()
Python:Pillow | Image Module | fromarray() | Codecademy
June 8, 2024 - L: It represents grayscale or shade of gray from white to black. It only has an 8-bit pixel to store its value. The example below shows the value of a pixel in coordinate (0,0) after the parameter mode is used with CMYK as the value. ... The result proves that the obj_array has been successfully generated as new_imageA, and the pixel at coordinate (0,0) is stored as a CMYK color combination with the values shown below.
🌐
Towards Data Science
towardsdatascience.com › home › artificial intelligence › deep learning › how rgb and grayscale images are represented in numpy arrays?
How RGB and Grayscale Images Are Represented in NumPy Arrays? | Towards Data Science
December 4, 2021 - In an RGB image where there are ... For example, the number 0 of a pixel in the red channel means that there is no red color in the pixel while the number 255 means that there is 100% red color in the pixel....
🌐
TutorialsPoint
tutorialspoint.com › how-to-show-numpy-2d-array-as-grayscale-image-in-jupyter-notebook
How to show numpy 2D array as grayscale image in Jupyter Notebook?
To show a 2D array as a grayscale image in Jupyter Notebook, we can take the following steps Steps Set the figure size and adjust the padding between and around the subplots. Create a random data u
🌐
Sbirchfield
sbirchfield.github.io › cvintro › lessons › lesson01_images_as_arrays.html
Lesson 1: Images As Arrays - Introduction to Computer Vision
... im = np.zeros((100, 100), dtype=np.uint8) im[20:80, 20:80] = 255 # a white square on a black background print('shape:', im.shape, 'dtype:', im.dtype) plt.imshow(im, cmap='gray', vmin=0, vmax=255) plt.title('Grayscale image (100x100)') plt.axis('off') plt.show()
🌐
Quora
quora.com › How-do-I-plot-a-grayscale-image-with-a-2D-array-of-random-numbers-in-Python
How to plot a grayscale image with a 2D array of random numbers in Python - Quora
Quora is a place to gain and share knowledge. It's a platform to ask questions and connect with people who contribute unique insights and quality answers.
🌐
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 - This might surprise you, but most issues stem from two simple mistakes: Shape mismatch errors If your array doesn’t have the correct shape, PIL won’t know how to interpret it. For example: A 2D array works for grayscale images (mode='L').
🌐
scikit-image
scikit-image.org › skimage-tutorials › lectures › 00_images_are_arrays.html
Images are numpy arrays — Image analysis in Python
Different colors contribute differently to the luminance: it’s very hard to have a bright, pure blue, for example. So, starting from an RGB image, the luminance is given by: ... Use Python 3.5’s matrix multiplication, @, to convert an RGB image to a grayscale luminance image according to the formula above.
🌐
Note.nkmk.me
note.nkmk.me › home › python › numpy
Image processing with Python, NumPy | note.nkmk.me
October 20, 2020 - pil_img = Image.fromarray(im) print(pil_img.mode) # RGB pil_img.save('data/temp/lena_save_pillow.jpg') ... A grayscale image (2D array) can also be passed to Image.fromarray(). mode automatically becomes 'L' (grayscale).
🌐
Pythoninformer
pythoninformer.com › python-libraries › numpy › numpy-and-images
PythonInformer - Image processing with pillow and NumPy
October 2, 2022 - For example, this code inverts a greyscale image (swapping black and white). and saves it back: import numpy as np from PIL import Image img = Image.open('testgrey.png') array = np.array(img) array = 255 - array invimg = Image.fromarray(array) invimg.save('testgrey-inverted.png')
Top answer
1 of 4
3

From what I understand, you're trying to display the numbers in your matrix as different shades of grey and make it large enough to fit on a poster. So, like @pandita, I would also use Matplotlib as this can be done pretty easily.

import matplotlib.pyplot as plt
import matplotlib.cm as cm
import numpy as np

height, width = 50, 33 #in pixels
spines = 'left', 'right', 'top', 'bottom'

labels = ['label' + spine for spine in spines]

tick_params = {spine : False for spine in spines}
tick_params.update({label : False for label in labels})

img = np.random.randint(0, 4097, (height, width))

img *= 255. / 4096

desired_width = 8 #in inches
scale = desired_width / float(width)

fig, ax = plt.subplots(1, 1, figsize=(desired_width, height*scale))
img = ax.imshow(img, cmap=cm.Greys_r, interpolation='none')

#remove spines
for spine in spines:
    ax.spines[spine].set_visible(False)

#hide ticks and labels
ax.tick_params(**tick_params)

#preview
plt.show()

#save
fig.savefig('test.png', dpi=300)

Produces the following image ...

2 of 4
1

To summarize, you have 50x33 image and you want to upsize to get a "decent resolution/size to be able to put it on a poster."

This class of problem is called super-resolution. It is an active research area. Some super-resolution algorithms are available as part of the opencv library. opencv has a python port. You can read about the available super-resolution algorithms here.

Depending on the type of image that you have, achieving a nice-looking 640x480 resolution image starting from 50x33 could be a bit of a stretch for even the best algorithms. You may need to temper your goals.