Friday, October 24, 2025
HomeLanguagesnumpy.ma.mask_rowcols() function | Python

numpy.ma.mask_rowcols() function | Python

In this numpy.ma.mask_rowcols() function, mask rows and/or columns of a 2D array that contain masked values. The masking behavior is selected using the axis parameter.
If axis is None, rows and columns are masked.
If axis is 0, only rows are masked.
If axis is 1 or -1, only columns are masked.

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.

Code #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)


Output :

[[0 0 -- 0]
 [0 0 -- 0]
 [-- -- -- --]
 [0 0 -- 0]]

 
Code #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)


Output :

[[0 0 0 -- 0]
 [0 0 0 -- 0]
 [0 0 0 -- 0]
 [-- -- -- -- --]
 [0 0 0 -- 0]]
Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS