1import numpy as np
2
3a = np.random.rand(3,2)
4
5# Normalised [0,1]
6b = (a - np.min(a))/np.ptp(a)
7
8# Normalised [0,255] as integer: don't forget the parenthesis before astype(int)
9c = (255*(a - np.min(a))/np.ptp(a)).astype(int)
10
11# Normalised [-1,1]
12d = 2.*(a - np.min(a))/np.ptp(a)-1