Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

function
python
communitycreator

What is the numpy.ma.getmask() function in Python?

Onyejiaku Theophilus Chidalu

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Overview

Python’s ma.getmask() function returns the mask of a masked array (i.e, the nomask).

Syntax

ma.getmask(a)

Parameter value

The ma.getmask() function takes the a value as a parameter. This represents an input MaskedArray for which the mask is required.

Return value

The ma.getmask() function returns an array of Boolean values indicating which input array elements are nomask or mask. It returns True if the element is mask and False if the element is nomask.

Example

import numpy as np
import numpy.ma as ma
# creating a MaskedArray with the element 3 as the mask
myarray = ma.masked_equal([[1,2],[3,4]], 3)
# implementing the ma.getmask() function
newarray = ma.getmask(myarray)
print(newarray)
Implementing the ma.getmask() function

Explanation

  • Line 1-2: We import the required module and library.
  • Line 5: We create a MaskedArray، myarray، which has its element 3 as the mask.
  • Line 8: We implement the ma.getmask() function on the input MaskedArray. The result is assigned to a variable newarray.
  • Line 10: We print the variable، newarray.

RELATED TAGS

function
python
communitycreator

CONTRIBUTOR

Onyejiaku Theophilus Chidalu

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring