Friday, October 3, 2025
HomeLanguagesnumpy.ma.mask_cols() function | Python

numpy.ma.mask_cols() function | Python

In thisnumpy.ma.mask_cols() function, mask columns of a 2D array that contain masked values. This function is a shortcut to mask_rowcols with axis equal to 1.

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.

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


Output :

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

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


Output :

[[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
32331 POSTS0 COMMENTS
Milvus
85 POSTS0 COMMENTS
Nango Kala
6703 POSTS0 COMMENTS
Nicole Veronica
11867 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11929 POSTS0 COMMENTS
Shaida Kate Naidoo
6818 POSTS0 COMMENTS
Ted Musemwa
7080 POSTS0 COMMENTS
Thapelo Manthata
6775 POSTS0 COMMENTS
Umr Jansen
6776 POSTS0 COMMENTS