numpy.MaskedArray.masked_outside()
函数用于屏蔽给定间隔之外的数组。此函数是masked_where的快捷方式,其中对于间隔外的arr,条件为True[v1, v2] (arr <v1)|(arr > v2)
。边界v1和v2可以任意顺序给出。
用法: numpy.ma.masked_outside(arr, v1, v2, copy=True)
参数:
arr :[ndarray]我们要屏蔽的输入数组。
v1,v2:[int]上限和下限。
copy :[bool]如果为True(默认),则在结果中复制arr。如果为False,则修改arr并返回视图。
Return :[MaskedArray]屏蔽后的结果数组。
代码1:
# Python program explaining
# numpy.MaskedArray.masked_outside() method
# importing numpy as geek
# and numpy.ma module as ma
import numpy as geek
import numpy.ma as ma
# creating input array
in_arr = geek.array([1, 2, 3, -1, 2])
print ("Input array:", in_arr)
# applying MaskedArray.masked_outside methods
mask_arr = ma.masked_outside(in_arr, -1, 1)
print ("Masked array:", mask_arr)
输出:
Input array: [ 1 2 3 -1 2] Masked array: [1 -- -- -1 --]
代码2:
# Python program explaining
# numpy.MaskedArray.masked_outside() method
# importing numpy as geek
# and numpy.ma module as ma
import numpy as geek
import numpy.ma as ma
# creating input array
in_arr = geek.array([5e8, 3e-5, -45.0, 4e4, 5e2])
print ("Input array:", in_arr)
# applying MaskedArray.masked_outside methods
mask_arr = ma.masked_outside(in_arr, 5e2, 5e8)
print ("Masked array:", mask_arr)
输出:
Input array: [ 5.0e+08 3.0e-05 -4.5e+01 4.0e+04 5.0e+02] Masked array: [500000000.0 -- -- 40000.0 500.0]
相关用法
- Python Numpy MaskedArray.sum()用法及代码示例
- Python Numpy MaskedArray.var()用法及代码示例
- Python Numpy MaskedArray.any()用法及代码示例
- Python Numpy MaskedArray.dot()用法及代码示例
- Python Numpy MaskedArray.mean()用法及代码示例
- Python Numpy MaskedArray.std()用法及代码示例
- Python Numpy MaskedArray.all()用法及代码示例
- Python Numpy MaskedArray.argsort()用法及代码示例
- Python Numpy MaskedArray.masked_invalid()用法及代码示例
- Python Numpy MaskedArray.prod()用法及代码示例
- Python Numpy MaskedArray.flatten()用法及代码示例
- Python Numpy MaskedArray.allequal()用法及代码示例
- Python Numpy MaskedArray.atleast_3d()用法及代码示例
- Python Numpy MaskedArray.cumprod()用法及代码示例
- Python Numpy MaskedArray.masked_not_equal()用法及代码示例
注:本文由纯净天空筛选整理自sanjoy_62大神的英文原创作品 Numpy MaskedArray masked_outside() function | Python。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。