Open In App

Numpy MaskedArray.masked_not_equal() function | Python

Last Updated : 27 Sep, 2019
Improve
Improve
Like Article
Like
Save
Share
Report

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_not_equal() function is used to mask an array where not equal to a given value.This function is a shortcut to masked_where, with condition = (arr != value).

Syntax : numpy.ma.masked_not_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 != 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_not_equal() method 
  
# importing numpy as geek 
# and numpy.ma module as ma
import numpy as geek
import numpy.ma as ma
  
# creating input array 
in_arr = geek.array([1, 2, 3, -1, 2])
print ("Input array : ", in_arr)
  
# applying MaskedArray.masked_not_equal methods 
# to input array where value != 2
mask_arr = ma.masked_not_equal(in_arr, 2)
print ("Masked array : ", mask_arr)


Output:

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

 

Code #2 :




# Python program explaining
# numpy.MaskedArray.masked_not_equal() method 
  
# importing numpy as geek 
# and numpy.ma module as ma
import numpy as geek
import numpy.ma as ma
  
# creating input array 
in_arr = geek.array([5e8, 3e-5, -45.0, 4e4, 5e2])
print ("Input array : ", in_arr)
  
# applying MaskedArray.masked_not_equal methods 
# to input array where value != 5e2
mask_arr = ma.masked_not_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 :  [-- -- -- -- 500.0]


Similar Reads

Numpy MaskedArray.atleast_3d() function | Python
numpy.MaskedArray.atleast_3d() function is used to convert inputs to masked arrays with at least three dimension.Scalar, 1-dimensional and 2-dimensional arrays are converted to 3-dimensional arrays, whilst higher-dimensional inputs are preserved. Syntax : numpy.ma.atleast_3d(*arys) Parameters: arys:[ array_like] One or more input arrays. Return : [
3 min read
Numpy MaskedArray.atleast_1d() function | Python
numpy.MaskedArray.atleast_1d() function is used to convert inputs to masked arrays with at least one dimension.Scalar inputs are converted to 1-dimensional arrays, whilst higher-dimensional inputs are preserved. Syntax : numpy.ma.atleast_1d(*arys) Parameters: arys:[ array_like] One or more input arrays. Return : [ ndarray] An array, or list of arra
2 min read
Numpy MaskedArray.atleast_2d() function | Python
numpy.MaskedArray.atleast_2d() function is used to convert inputs to masked arrays with at least two dimension.Scalar and 1-dimensional arrays are converted to 2-dimensional arrays, whilst higher-dimensional inputs are preserved. Syntax : numpy.ma.atleast_2d(*arys) Parameters: arys:[ array_like] One or more input arrays. Return : [ ndarray] An arra
2 min read
Numpy MaskedArray.all() 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. nump
3 min read
Numpy MaskedArray.argsort() 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
3 min read
Numpy MaskedArray.argmax() 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
3 min read
Numpy MaskedArray.argmin() 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
3 min read
Numpy MaskedArray.any() 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
3 min read
Numpy MaskedArray.anom() 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
2 min read
Numpy MaskedArray.masked_less() 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
2 min read
Article Tags :
Practice Tags :