Numpy MaskedArray.masked_less_equal() function | Python
In many circumstances, datasets can be incomplete or tainted by the presence of invalid data. For example, a sensor may have failed to record a data, or recorded an invalid value. The
numpy.ma module provides a convenient way to address this issue, by introducing masked arrays.Masked arrays are arrays that may have missing or invalid entries.
numpy.MaskedArray.masked_less_equal() function is used to mask an array where less than or equal to a given value.This function is a shortcut to
condition = (arr <= value).
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning - Basic Level Course
numpy.ma.masked_greater_equal(arr, value, copy=True)
arr : [ndarray] Input array which we want to mask.
value : [int] It is used to mask the array element which are <= 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 :
Input array : [ 1 2 3 -1 2] Masked array : [-- -- 3 -- --]
Code #2 :
Input array : [ 5.0e+08 3.0e-05 -4.5e+01 4.0e+04 5.0e+02] Masked array : [500000000.0 -- -- 40000.0 --]