Skip to content
Related Articles

Related Articles

Improve Article

numpy.ma.clump_unmasked() function | Python

  • Last Updated : 22 Apr, 2020

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

Syntax : numpy.ma.clump_unmasked(arr)

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

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

Code #1 :






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

Output :

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

 
Code #2 :




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

Output :

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

 Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.  

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course




My Personal Notes arrow_drop_up
Recommended Articles
Page :