Friday, September 26, 2025
HomeLanguagesnumpy.ma.compress_cols() function in Python

numpy.ma.compress_cols() function in Python

Prerequisite: numpy

This numpy inbuilt function suppresses whole columns that contain masked values in a 2-D array.

Syntax:  numpy.ma.compress_cols(arr)

Parameters : 

arr : [array_like, MaskedArray]

  1. This parameter holds the array to operate on.
  2. The array must be a 2D array.
  3. If no array elements are masked, arr is interpreted as a MaskedArray with mask set to nomask.
     

Return : Returns the compressed array.

Below is the Implementation of the above function.

Example 1:

Python3




# importing numpy as geek
import numpy as geek
  
# defining an array with mask
arr = geek.ma.array(geek.arange(6).reshape(2, 3),
                    mask=[[1, 0, 0], [0, 0, 0]])
  
# applying mask to array elements
gfg = geek.ma.compress_cols(arr)
  
print(gfg)


Output :  

[[1 2]
 [4 5]]

Example 2:

Python3




# importing numpy as geek
import numpy as geek
  
# defining array
arr = geek.ma.array(geek.arange(9).reshape(3, 3), mask=[
                    [1, 0, 0], [1, 0, 0], [0, 0, 0]])
  
# applying mask to array elements
gfg = geek.ma.compress_cols(arr)
  
print(gfg)


Output : 

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

Most Popular

Dominic
32320 POSTS0 COMMENTS
Milvus
84 POSTS0 COMMENTS
Nango Kala
6683 POSTS0 COMMENTS
Nicole Veronica
11854 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11910 POSTS0 COMMENTS
Shaida Kate Naidoo
6795 POSTS0 COMMENTS
Ted Musemwa
7071 POSTS0 COMMENTS
Thapelo Manthata
6755 POSTS0 COMMENTS
Umr Jansen
6762 POSTS0 COMMENTS