Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

function
python
communitycreator

What is the numpy.ma.masked_all_like() 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.

Answers Code

Overview

The ma.masked_all_like() function in Python empties a masked array with the properties of an existing array.

Syntax

ma.masked_all_like(arr)

Parameter

The ma.masked_all_like() function takes the parameter value arr, which represents an input array with the same shape and data type as the required MaskedArray.

Return type

The ma.masked_all_like() function returns a masked array where all the data are masked.

Example

import numpy as np
import numpy.ma as ma
# creating an array
myarray = np.array([[1,2,3], [4,5,6]])
# implementing the ma.masked_all_like() function
newarray = ma.masked_all_like(myarray)
# printing the old array
print(myarray)
# printing the masked array
print(newarray)
implementing the ma.masked_all_like() function

Explanation

  • Line 1 and 2: We import the required modules.
  • Line 5: We create an input array, myarray, using the array() function.
  • Line 8: We implement the ma.masked_all_like() function on the input array. The result is assigned to a variable, newarray.
  • Line 11: We print the input array, myarray.
  • Line 14: We print the masked array 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.

Answers Code
Keep Exploring