Thursday, July 4, 2024
HomeLanguagesPythonPython | Numpy getmask() method

Python | Numpy getmask() method

With the help of numpy.getmask() method, we can get the masked matrix of numpy array which shows masked values by using numpy.getmask() method.

Syntax : numpy.getmask(array)

Return : Return masked values of a matrix.

Example #1 :

In this example we can see that by using numpy.getmask() method, we are able to get the masked matrix of an array.




# import numpy
import numpy.ma as ma
  
gfg = ma.masked_equal([[1, 2], [5, 6]], 5)
  
# using numpy.getmask() method
print(ma.getmask(gfg))


Output :

[[False False]
[ True False]]

Example #2 :




# import numpy
import numpy.ma as ma
  
gfg = ma.masked_equal([11, 12, 13, 14, 15], 12)
  
# using numpy.getmask() method
print(ma.getmask(gfg))


Output :

[False True False False False]

Ted Musemwa
As a software developer I’m interested in the intersection of computational thinking and design thinking when solving human problems. As a professional I am guided by the principles of experiential learning; experience, reflect, conceptualise and experiment.
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments