Friday, September 5, 2025
HomeLanguagesnumpy.ma.compress_rowcols() function in Python

numpy.ma.compress_rowcols() function in Python

numpy.ma.compress_rowcols() function suppresses rows and columns that contain masked values in a 2-D array. 
The suppression behavior is selected with the axis parameter: 

  • If axis is None, both rows and columns are suppressed.
  • If axis is 0, only rows are suppressed.
  • If axis is 1 or -1, only columns are suppressed.

Syntax : numpy.ma.compress_rowcols(arr, axis = None) 

Parameters : 
arr : [array_like, MaskedArray] This parameter holds the array to operate on.The array must be a 2D array. If no array elements are masked, arr is interpreted as a MaskedArray with mask set to nomask. 
axis : [int, optional] Axis along which to perform the operation. Default is None. 

Return : Return the compressed array.

Code #1: 

Python3




# Python program explaining
# numpy.ma.compress_rowcols() function
  
# importing numpy as geek
import numpy as geek
  
arr = geek.ma.array(geek.arange(6).reshape(2, 3),
                    mask=[[1, 0, 0], [0, 0, 0]])
  
gfg = geek.ma.compress_rowcols(arr)
  
print(gfg)


Output: 

[[4 5]]

Code #2: 

Python3




# Python program explaining
# numpy.ma.compress_rowcols() function
  
# importing numpy as geek
import numpy as geek
  
arr = geek.ma.array(geek.arange(6).reshape(2, 3),
                    mask=[[1, 0, 0], [0, 0, 0]])
  
gfg = geek.ma.compress_rowcols(arr, 1)
  
print(gfg)


Output:

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

Most Popular

Dominic
32264 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6634 POSTS0 COMMENTS
Nicole Veronica
11801 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11863 POSTS0 COMMENTS
Shaida Kate Naidoo
6750 POSTS0 COMMENTS
Ted Musemwa
7025 POSTS0 COMMENTS
Thapelo Manthata
6701 POSTS0 COMMENTS
Umr Jansen
6718 POSTS0 COMMENTS