numpy.MaskedArray.common_fill_value()
函数用于返回两个掩码数组之间的公共填充值。arr1.fill_value == arr2.fill_value
然后返回填充值,否则返回无。
用法: numpy.ma.common_fill_value(arr1, arr2)
参数:
arr1,arr2:[MaskedArray]要为其比较填充值的被遮罩的数组。
Return :[标量或无]通用填充值或无。
代码1:
# Python program explaining
# numpy.MaskedArray.common_fill_value() method
# importing numpy as geek
# and numpy.ma module as ma
import numpy as geek
import numpy.ma as ma
# creating input arrays
in_arr1 = geek.array([[1, 2], [ 3, -1], [ 5, -3]])
print ("1st Input array:", in_arr1)
in_arr2 = geek.array([[10, 20], [ 30, -10], [ 50, -30]])
print ("2nd Input array:", in_arr2)
# Now we are creating masked arrays.
# by making entry as invalid.
mask_arr1 = ma.masked_array(in_arr1, mask =[[1, 0], [ 1, 0], [ 0, 0]],
fill_value = 5)
print ("1st Masked array:", mask_arr1)
mask_arr2 = ma.masked_array(in_arr2, mask =[[1, 1], [ 1, 0], [ 0, 0]],
fill_value = 5)
print ("2nd Masked array:", mask_arr2)
# applying MaskedArray.common_fill_value
# methods to masked array
out_arr = ma.common_fill_value(mask_arr1, mask_arr2)
print ("common filled value:", out_arr)
输出:
1st Input array: [[ 1 2] [ 3 -1] [ 5 -3]] 2nd Input array: [[ 10 20] [ 30 -10] [ 50 -30]] 1st Masked array: [[-- 2] [-- -1] [5 -3]] 2nd Masked array: [[-- --] [-- -10] [50 -30]] common filled value: 5
代码2:
# Python program explaining
# numpy.MaskedArray.common_fill_value() method
# importing numpy as geek
# and numpy.ma module as ma
import numpy as geek
import numpy.ma as ma
# creating input arrays
in_arr1 = geek.array([[1, 2], [ 3, -1], [ 5, -3]])
print ("1st Input array:", in_arr1)
in_arr2 = geek.array([[10, 20], [ 30, -10], [ 50, -30]])
print ("2nd Input array:", in_arr2)
# Now we are creating masked arrays.
# by making entry as invalid.
mask_arr1 = ma.masked_array(in_arr1, mask =[[1, 0], [ 1, 0], [ 0, 0]],
fill_value = 5)
print ("1st Masked array:", mask_arr1)
mask_arr2 = ma.masked_array(in_arr2, mask =[[1, 1], [ 1, 0], [ 0, 0]],
fill_value = 10)
print ("2nd Masked array:", mask_arr2)
# applying MaskedArray.common_fill_value
# methods to masked array
out_arr = ma.common_fill_value(mask_arr1, mask_arr2)
print ("common filled value:", out_arr)
输出:
1st Input array: [[ 1 2] [ 3 -1] [ 5 -3]] 2nd Input array: [[ 10 20] [ 30 -10] [ 50 -30]] 1st Masked array: [[-- 2] [-- -1] [5 -3]] 2nd Masked array: [[-- --] [-- -10] [50 -30]] common filled value: None
相关用法
- Python numpy.cov()用法及代码示例
- Python numpy.copyto()用法及代码示例
- Python Numpy MaskedArray.any()用法及代码示例
- Python Numpy MaskedArray.var()用法及代码示例
- Python Numpy MaskedArray.sum()用法及代码示例
- Python numpy.issubsctype()用法及代码示例
- Python Numpy MaskedArray.std()用法及代码示例
- Python Numpy MaskedArray.mean()用法及代码示例
- Python Numpy recarray.put()用法及代码示例
- Python Numpy recarray.ptp()用法及代码示例
- Python Numpy MaskedArray.all()用法及代码示例
- Python Numpy MaskedArray.dot()用法及代码示例
- Python Numpy recarray.all()用法及代码示例
注:本文由纯净天空筛选整理自jana_sayantan大神的英文原创作品 Numpy MaskedArray.common_fill_value() function | Python。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。