Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

numpy
python
communitycreator

What is the ma.masked_less() function in NumPy?

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

The masked_less() function in NumPy masks an array where the value of the array's element is less than the specified value in the function.

Syntax

The masked_less() function takes the following syntax:

ma.masked_less(x, value)
The syntax for the masked_less() function

Parameter value

The masked_less() function takes the following parameter values:

  • x: This is the input array and is a required parameter.
  • value: This is the value to which elements of the array are masked if they are greater. It is a required parameter.

Return value

The masked_less() function returns a masked array.

Example

# A code to illustrate the masked_less() function
# importing the necessary libraries
import numpy as np
import numpy.ma as ma
# creating an input array
my_array = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
# masking the values Less than 5
mask_array =ma.masked_less(my_array, 5)
# printing the masked array
print(mask_array)
Implement the masked_less() function

Explanation

  • Line 4-5: We import the necessary library and module.
  • Line 8: We create an input array, my_array.
  • Line 11: We mask the values less than 5 in the input array using the masked_less() function. The result is assigned to a variable, mask_array.
  • Line 14: We print mask_array.

RELATED TAGS

numpy
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