Sunday, October 5, 2025
HomeLanguagesnumpy.ma.clump_masked() function | Python

numpy.ma.clump_masked() function | Python

numpy.ma.clump_masked() function returns a list of slices corresponding to the masked clumps of a 1-D array.

Syntax : numpy.ma.clump_masked(arr)

Parameters :
arr : [ndarray] A one-dimensional masked array.

Return : [list of slice] The list of slices, one for each continuous region of masked elements in arr.

Code #1 :




# Python program explaining
# numpy.ma.clump_masked() function
  
# importing numpy as geek  
# and numpy.ma module as ma 
import numpy as geek 
import numpy.ma as ma 
  
arr = geek.ma.masked_array(geek.arange(8))
arr[[0, 1, 2, 6]] = geek.ma.masked
   
gfg = geek.ma.clump_masked(arr)
  
print (gfg)


Output :

[slice(0, 3, None), slice(6, 7, None)]

 
Code #2 :




# Python program explaining
# numpy.ma.clump_masked() function
  
# importing numpy as geek  
# and numpy.ma module as ma 
import numpy as geek 
import numpy.ma as ma 
  
arr = geek.ma.masked_array(geek.arange(10))
arr[[0, 1, 2, 6, 8, 9]] = geek.ma.masked
   
gfg = geek.ma.clump_masked(arr)
  
print (gfg)


Output :

[slice(0, 3, None), slice(6, 7, None), slice(8, 10, None)]
Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32337 POSTS0 COMMENTS
Milvus
86 POSTS0 COMMENTS
Nango Kala
6706 POSTS0 COMMENTS
Nicole Veronica
11871 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11934 POSTS0 COMMENTS
Shaida Kate Naidoo
6823 POSTS0 COMMENTS
Ted Musemwa
7089 POSTS0 COMMENTS
Thapelo Manthata
6779 POSTS0 COMMENTS
Umr Jansen
6779 POSTS0 COMMENTS