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

what is the .shape of temp_array?

your files are. because whatever you’re giving to the imwrite call is malformed.

uh yes it will, if the array has the right shape and dtype.

MRE is required.

the code you present is missing some definitions.

MRE” also means you must replace/mock all the serial stuff. nobody except you has this hardware device. insert the required data so the script runs standalone.