mask = pixel_array == paddingVal
byte_array[mask] = 0
byte_array[~mask] = np.round(255.0 * (pixel_array[~mask] - minVal) / (
    maxVal - minVal - 1.0))
What is an efficient way to scale a int16 numpy array to a int8 numpy array