numpy.ma.mask_rowcols()函数| Python
在这个numpy.ma.mask_rowcols()
函数中,屏蔽包含屏蔽值的二维数组的行和/或列。使用轴参数选择掩蔽行为。
如果轴是无,行和列被屏蔽。
如果轴为 0,则仅屏蔽行。
如果轴为 1 或 -1,则仅屏蔽列。
Syntax : numpy.ma.mask_rowcols(arr, axis = None)
Parameters :
arr : [array_like, MaskedArray] The array to mask. The result is a MaskedArray with mask set to nomask (False). Must be a 2D array.
axis : [int, optional] Axis along which to perform the operation. Default is None.
Return : [MaskedArray] A modified version of the input array, masked depending on the value of the axis parameter.
代码#1:
# Python program explaining
# numpy.ma.mask_rowcols() function
# importing numpy as geek
# and numpy.ma module as ma
import numpy as geek
import numpy.ma as ma
arr = geek.zeros((4, 4), dtype = int)
arr[2, 2] = 1
arr = ma.masked_equal(arr, 1)
gfg = ma.mask_rowcols(arr)
print (gfg)
输出 :
[[0 0 -- 0]
[0 0 -- 0]
[-- -- -- --]
[0 0 -- 0]]
代码#2:
# Python program explaining
# numpy.ma.mask_rowcols() function
# importing numpy as geek
# and numpy.ma module as ma
import numpy as geek
import numpy.ma as ma
arr = geek.zeros((5, 5), dtype = int)
arr[3, 3] = 1
arr = ma.masked_equal(arr, 1)
gfg = ma.mask_rowcols(arr)
print (gfg)
输出 :
[[0 0 0 -- 0]
[0 0 0 -- 0]
[0 0 0 -- 0]
[-- -- -- -- --]
[0 0 0 -- 0]]