numpy.ma.notmasked_edges() function | Python

numpy.ma.notmasked_edges() function find the indices of the first and last unmasked values along an axis.
Return None, if all values are masked. Otherwise, return a list of two tuples, corresponding to the indices of the first and last unmasked values respectively.

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

Parameters :
arr : [array_like] The input array.
axis : [int, optional] Axis along which to perform the operation. Default is None.

Return : [ ndarray or list] An array of start and end indexes if there are any masked data in the array. If there are no masked data in the array, edges is a list of the first and last index.

Code #1 :



filter_none

edit
close

play_arrow

link
brightness_4
code

# Python program explaining
# numpy.ma.notmasked_edges() function
  
# importing numpy as geek  
# and numpy.ma module as ma 
import numpy as geek 
import numpy.ma as ma 
  
arr = geek.arange(12).reshape((3, 4))
  
gfg = geek.ma.notmasked_edges(arr)
  
print (gfg)

chevron_right


Output :

[ 0, 11]

 
Code #2 :

filter_none

edit
close

play_arrow

link
brightness_4
code

# Python program explaining
# numpy.ma.notmasked_edges() function
  
# importing numpy as geek  
# and numpy.ma module as ma 
import numpy as geek 
import numpy.ma as ma 
  
arr = geek.arange(12).reshape((3, 4))
m = geek.zeros_like(arr)
m[1:, 1:] = 1
  
am = geek.ma.array(arr, mask = m)
  
gfg = geek.ma.notmasked_edges(am)
  
print (gfg)

chevron_right


Output :

[0, 8]
My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.