numpy.ma.mask_cols()函数| Python
在这个numpy.ma.mask_cols()
函数中,屏蔽包含屏蔽值的二维数组的列。此函数是轴等于 1 的 mask_rowcols 的快捷方式。
Syntax : numpy.ma.mask_cols(arr, axis = None)
Parameters :
arr : [array_like, MaskedArray] The array to mask.
axis : [int, optional] Axis along which to perform the operation. Default is None.
Return : [MaskedArray] A modified version of the input array.
代码#1:
# Python program explaining
# numpy.ma.mask_cols() function
# importing numpy as geek
# and numpy.ma module as ma
import numpy as geek
import numpy.ma as ma
arr = geek.zeros((3, 3), dtype = int)
arr[1, 1] = 1
arr = ma.masked_equal(arr, 1)
gfg = ma.mask_cols(arr)
print (gfg)
输出 :
[[0 -- 0]
[0 -- 0]
[0 -- 0]]
代码#2:
# Python program explaining
# numpy.ma.mask_cols() 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_cols(arr)
print (gfg)
输出 :
[[0 0 -- 0]
[0 0 -- 0]
[0 0 -- 0]
[0 0 -- 0]]