Friday, October 10, 2025
HomeLanguagesnumpy.ma.notmasked_contiguous function | Python

numpy.ma.notmasked_contiguous function | Python

numpy.ma.notmasked_contiguous() function find contiguous unmasked data in a masked array along the given axis.

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

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

Return : [list] A list of slices (start and end indexes) of unmasked indexes in the array. If the input is 2d and axis is specified, the result is a list of lists.

Code #1 :




# Python program explaining
# numpy.ma.notmasked_contiguous() 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))
mask = geek.zeros_like(arr)
mask[1:, :-1] = 1; mask[0, 1] = 1; mask[-1, 0] = 0
ma = geek.ma.array(arr, mask = mask)
  
gfg = geek.ma.notmasked_contiguous(ma)
  
print (gfg)


Output :

[slice(0, 1, None), slice(2, 4, None), slice(7, 9, None), slice(11, 12, None)]

 
Code #2 :




# Python program explaining
# numpy.ma.notmasked_contiguous() 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))
mask = geek.zeros_like(arr)
mask[1:, :-1] = 1; mask[0, 1] = 1; mask[-1, 0] = 0
ma = geek.ma.array(arr, mask = mask)
  
gfg = geek.ma.notmasked_contiguous(ma, axis = 1)
  
print (gfg)


Output :

[[slice(0, 1, None), slice(2, 4, None)], [slice(3, 4, None)], [slice(0, 1, None), slice(3, 4, None)]]

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32349 POSTS0 COMMENTS
Milvus
87 POSTS0 COMMENTS
Nango Kala
6715 POSTS0 COMMENTS
Nicole Veronica
11878 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11941 POSTS0 COMMENTS
Shaida Kate Naidoo
6837 POSTS0 COMMENTS
Ted Musemwa
7097 POSTS0 COMMENTS
Thapelo Manthata
6792 POSTS0 COMMENTS
Umr Jansen
6791 POSTS0 COMMENTS