参数数量及其作用
np.clip是一个截取函数,用于截取数组中小于或者大于某值的部分,并使得被截取部分等于固定值。
函数如下:
np.clip( a, a_min, a_max, out=None):
该函数的作用是将数组a中的所有数限定到范围a_min和a_max中。
部分参数解释:
a:输入矩阵;
a_min:被限定的最小值,所有比a_min小的数都会强制变为a_min;
a_max:被限定的最大值,所有比a_max大的数都会强制变为a_max;
out:可以指定输出矩阵的对象,shape与a相同
示例
import numpy as np # 一维矩阵 x= np.arange(12) print(np.clip(x,3,8)) # 多维矩阵 y= np.arange(12).reshape(3,4) print(np.clip(y,3,8))
实验结果为:
[3 3 3 3 4 5 6 7 8 8 8 8] [[3 3 3 3] [4 5 6 7] [8 8 8 8]]
原文链接:https://blog.csdn.net/weixin_44791964/article/details/100000373