📜  如何在两个值之间缩放数组python代码示例

📅  最后修改于: 2022-03-11 14:47:07.685000             🧑  作者: Mango

代码示例1
import numpy as np

a = np.random.rand(3,2)

# Normalised [0,1]
b = (a - np.min(a))/np.ptp(a)

# Normalised [0,255] as integer: don't forget the parenthesis before astype(int)
c = (255*(a - np.min(a))/np.ptp(a)).astype(int)        

# Normalised [-1,1]
d = 2.*(a - np.min(a))/np.ptp(a)-1