python中np.clip()函数

clip()截断,限制数组的上下界

np.clip(a,min,max,out = None)

示例:

t = np.random.randn(4,5)
print(t)
print(np.clip(2*t,-1,1))

'''
输出结果为:

[[ 1.09910613 -0.2808202   0.42589793 -0.12338178 -1.48311223]
 [-1.47979074 -2.30738852  1.63174218  0.46779453  1.04298927]
 [-0.83214921  0.04515663  1.52932098 -0.0438187  -0.66773409]
 [-1.26371749  0.29859958  0.28911259 -0.0295001  -0.84024894]]
 
[[ 1.         -0.56164039  0.85179586 -0.24676355 -1.        ]
 [-1.         -1.          1.          0.93558905  1.        ]
 [-1.          0.09031326  1.         -0.0876374  -1.        ]
 [-1.          0.59719916  0.57822517 -0.0590002  -1.        ]]
'''

你可能感兴趣的:(python,python)