Scale a numpy array with from -0.1 - 0.2 to 0-255

new_arr = ((arr + 0.1) * (1/0.3) * 255).astype('uint8')

This first scales the vector to the [0, 1] range, multiplies it by 255 and then converts it to uint8, which is a common format for images (opencv uses it, for example)

In general you can use:

new_arr = ((arr - arr.min()) * (1/(arr.max() - arr.min()) * 255)).astype('uint8')

You can also use uint8 datatype while storing the image from numpy array.

import numpy as np from PIL import Image img = Image.fromarray(np.uint8(tmp))

tmp is my np array of size 255*255*3.