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

Hi,

I need to create the image by hand so to speak because I eventually want to pass it to the Meijer algorithm. An implementation of the same using a camera is at the following link.
https://www.seeingwithsound.com/hificode_OpenCV.py

I have made some progress after reading your messages and doing some more reading. See below for a minimum reusable implementation.
Note:
I have tried playing the array values which sort of works in the sense that I get different clicks as I move the sensor around.

The shape of the array is 64 64.

import sys import random import maxSonarTTY import numpy as np import cv2 import sounddevice as sd 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=
fs = 44100
#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)
    image_array=np.empty([64, 64],np.uint8)
    for lc in range(len(scaled_readings)):
        scaled_readings_value=scaled_readings[lc]
        image_array[lc][lc]=scaled_readings_value

    print("shape of array=",image_array.shape)
    
    cv2.imwrite('image_img.png', image_array)
    sd.play(np.array(raw_sonar_readings,np.uint8), fs)
    print("image written")
    raw_sonar_readings.clear()