Numpy MaskedArray.masked_less_equal () function | python

numpy.MaskedArray.masked_less_equal() is used to mask an array where the value is less than or equal to the specified masked_where function is a shortcut to masked_where with condition = (arr & lt; = value).

Syntax: numpy.ma. masked_greater_equal (arr, value, copy = True)

Parameters:
arr: [ndarray] Input array which we want to mask.
value: [int] It is used to mask the array element which are & lt; = value.
copy: [bool ] If True (default) make a copy of arr in the result. If False modify arr in place and return a view.

Return: [MaskedArray] The resultant array after masking.

Code # 1:

# Python program explaining
# numpy. MaskedArray.masked_less_equal () method

 
# import numy as a geek
# and the numpy.ma module as ma

import numpy as geek

import numpy.ma as ma

 
# create input array

in_arr = geek.array ([ 1 , 2 , 3 , - 1 , 2 ])

print ( "Input array:" , in_arr )

 
# applying MaskedArray.masked_less_equal methods
# to enter an array where the value is & lt; = 2

mask_arr = ma.masked_less_equal (in_arr, 2 )

print ( "Masked array:" , mask_ arr)

Output:

 Input array: [1 2 3 -1 2] Masked array: [- - 3 - -] 

Code # 2:

# Python program explaining
# numpy.MaskedArray.masked_less_equal () method

 
# import numy as a geek
# and the numpy.ma module as ma

import numpy as geek

import numpy.ma as ma

  
# create input array

in_arr = geek.array ([ 5e8 , 3e - 5 , - 45.0 , 4e4 , 5e2 ])

print ( "Input array:" , in_arr)

 
# applying MaskedArray.masked_less_equal methods
# to enter an array where the value is & lt; = 5e2

mask_arr = ma.masked_less_equal (in_arr, 5e2 )

print ( "Masked array:" , mask_arr)

Output:

 Input array: [5.0e + 08 3.0e-05 -4.5e + 01 4.0e + 04 5.0e + 02] Masked array: [500000000.0 - - 40000.0 -] 




Get Solution for free from DataCamp guru