numpy.ma.mask_rows() function | Python

In this numpy.ma.mask_rows() function, mask rows of a 2D array that contain masked values. This function is a shortcut to mask_rowcols with axis equal to 0.

Syntax : numpy.ma.mask_rows(arr, axis = None)
Parameters :
arr : [array_like, MaskedArray] The array to mask. The result is a MaskedArray.
axis : [int, optional] Axis along which to perform the operation. Default is None.

Return : [MaskedArray] A modified version of the input array.

Code #1 :

filter_none

edit
close

play_arrow

link
brightness_4
code

# 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_rows(arr)
  
print (gfg)

chevron_right


Output :

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

 
Code #2 :

filter_none

edit
close

play_arrow

link
brightness_4
code

# Python program explaining
# numpy.ma.mask_rows() 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_rows(arr)
  
print (gfg)

chevron_right


Output :

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



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.