Building a gray scale image via a numpy array from ultrasonic sensor values

Hi,
The shape of temp_array is 64.
I have created minimum reproducible code below.

import random
import maxSonarTTY
import numpy as np
import cv2
def scale_number(unscaled, to_min, to_max, from_min, from_max):
    return (to_max-to_min)*(unscaled-from_min)/(from_max-from_min)+to_min

def scale_list(l, to_min, to_max):
    return [scale_number(i, to_min, to_max, min(l), max(l)) for i in l]
m=0
raw_sonar_readings=[]
#Warning, this program goes into an infinite loop. Break out of it by hitting ctrl+c
while True:
    
    #m=maxSonarTTY.measure("/dev/ttyUSB0") #Commenting out this line to create a mre
    m=random.uniform(500, 5000) #minik the distance values from the ultrasonic sensor
    raw_sonar_readings.append(m)
    if len(raw_sonar_readings)==64:
        #using one of the functions found at https://stackoverflow.com/questions/929103/convert-a-number-range-to-another-range-maintaining-ratio
        scaled_readings=scale_list(raw_sonar_readings,0,255)
        temp_array=np.array(scaled_readings,dtype=np.uint8)
        print("shape of array=",temp_array.shape)
        cv2.imwrite('image_img.png', temp_array)
        print("image written")
        raw_sonar_readings.clear()