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

matplotlib - How can I convert an RGB image into grayscale in Python? - Stack Overflow
Shouldn't be 0.2990 * R + 0.5870 * G + 0.1140 * B instead? The weight sum should equal to 1 and not 0.9999. Check here: en.wikipedia.org/wiki/Grayscale ... If an alpha (transparency) channel is present in the input image and should be preserved, use mode LA: 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
python - how to save an array as a grayscale image with matplotlib/numpy? - Stack Overflow
I am trying to save a numpy array of dimensions 128x128 pixels into a grayscale image. I simply thought that the pyplot.imsave function would do the job but it's not, it somehow converts my array i... 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 - The desired output is a grayscale image file, interpretable by common image viewing software. Matplotlib, a popular plotting library for Python, can be used to convert a NumPy array to a grayscale image and save it directly to a file.
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.

🌐
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.
Find elsewhere
🌐
Saskeli
saskeli.github.io › data-analysis-with-python-summer-2019 › image_processing.html
Image processing — Data analysis with Python - Summer 2019 documentation
def fadex(image): height, width ... ... This exercise can give two points at maximum! ... Write a function to_grayscale that takes an RGB image (three dimensional array) and returns a two dimensional gray-scale image....
🌐
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 - It’s a fundamental package for scientific computing with Python. 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-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.
🌐
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.
🌐
Codepointtech
codepointtech.com › home › grayscale image processing with numpy: a python guide
Grayscale Image Processing with NumPy: A Python Guide - codepointtech.com
July 4, 2026 - # Convert NumPy array back to Pillow Image gray_pil_img = Image.fromarray(gray_luminosity) bright_pil_img = Image.fromarray(bright_img) contrast_pil_img = Image.fromarray(contrast_img) inverted_pil_img = Image.fromarray(inverted_img) # Save the images gray_pil_img.save("grayscale_luminosity.jpg") bright_pil_img.save("grayscale_bright.jpg") contrast_pil_img.save("grayscale_contrast.jpg") inverted_pil_img.save("grayscale_inverted.jpg") print("Grayscale images saved successfully!") Grayscale image processing with NumPy is a fundamental skill for anyone working with digital images in Python.
🌐
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 - We’ll use Image.fromarray() again, but with a small twist—this time, we’ll specify the mode as 'L'. The 'L' mode tells PIL to treat the image as grayscale. from PIL import Image # Convert grayscale array to a PIL Image grayscale_img = ...
🌐
Delft Stack
delftstack.com › home › howto › python › convert image to grayscale python
How to Convert Image to Grayscale in Python | Delft Stack
February 2, 2024 - We need to multiply the complete matrices with the values given in the formula to get the grayscale image. The below code example demonstrates how we can implement the RGB to grayscale conversion formula in Python using the Matplotlib library.
🌐
Reddit
reddit.com › r/learnpython › how do i convert from grayscale to black and white?
r/learnpython on Reddit: How do I convert from grayscale to black and white?
September 24, 2023 -

Consider the following image:

Image

If you zoom in, you will observe that the picture contains pixels of the form (0,0,0,x) in RGBA format (I have used pillow to verify this btw). What I want to do is if the pixel's alpha is less than equal to 200, then write (0,0,0,0) at the pixel's place, and if it is greater than 200 then write (0,0,0,255) at the pixel's place.

Here's my code rn:

from PIL import Image
import numpy as np

def inp_gen(img_path):
    im = Image.open(img_path, 'r')
    pix_vals = list(im.getdata())
    layer = [x[3] for x in pix_vals]
    for j in layer:
        if j <= 200:
            layer[layer.index(j)] = 0
        if j > 200:
            layer[layer.index(j)] = 1 
    return layer

def render_img(img_data):
    image_data = [(0,0,0,255*x) for x in img_data]
    data = np.array(image_data, dtype=np.uint8).T
    image = Image.fromarray(data)
    image.show() 

render_img(img_gen("Path to image in drive link on my PC"))

Sadly, this does not give me the output I want:

Output

So what should I do now?