numpy.ma.masked_values() function | Python (original) (raw)
Last Updated : 05 May, 2020
numpy.ma.masked_values()
function return a MaskedArray, masked where the data in array arr are approximately equal to value, determined using isclose. The default tolerances for masked_values are the same as those for isclose.
Syntax : numpy.ma.masked_values(arr, value, rtol = 1e-05, atol = 1e-08, copy = True, shrink = True)
Parameter :
arr : [array_like] Array to mask.
value : [float] Masking value.
rtol, atol : [float, optional] Must be convertible to an array of booleans with the same shape as data. True indicates a masked data.
copy : [bool, optional] Whether to return a copy of arr.
shrink : [bool, optional] Whether to collapse a mask full of False to nomask.Return : [MaskedArray] The result of masking arr where approximately equal to value.
Code #1 :
import
numpy as geek
import
numpy.ma as ma
arr
=
geek.array([
1
,
1.5
,
2
,
1.5
,
3
])
gfg
=
ma.masked_values(arr,
1.5
)
print
(gfg)
Output :
[1.0 -- 2.0 -- 3.0]
Code #2 :
import
numpy as geek
import
numpy.ma as ma
arr
=
geek.array([
1
,
2
,
3
,
4
,
5
,
6
])
gfg
=
ma.masked_values(arr,
4
)
print
(gfg)
Output :
[1 2 3 -- 5 6]
Similar Reads
- numpy.ma.mask_rows() function | Python In this numpy.ma.mask_rows() function, mask rows of a 2D array that contain masked values. This function is a shortcut to mask_rowcols with axis equal to 0. Syntax : numpy.ma.mask_rows(arr, axis = None) Parameters : arr : [array_like, MaskedArray] The array to mask. The result is a MaskedArray. axis 2 min read
- numpy.ma.is_masked() function | Python numpy.ma.is_masked() function determine whether input has masked values & accepts any object as input, but always returns False unless the input is a MaskedArray containing masked values. Syntax : numpy.ma.is_masked(arr) Parameters : arr : [array_like] Array to check for masked values. Return : 1 min read
- numpy.ma.masked_all() function | Python numpy.ma.masked_all() function return an empty masked array of the given shape and dtype, where all the data are masked. Syntax : numpy.ma.masked_all(shape, dtype) Parameter : shape : [tuple] Shape of the required MaskedArray. dtype : [dtype, optional] Data type of the output. Return : [MaskedArray] 1 min read
- numpy.ma.mask_rowcols() function | Python In this numpy.ma.mask_rowcols() function, mask rows and/or columns of a 2D array that contain masked values. The masking behavior is selected using the axis parameter. If axis is None, rows and columns are masked. If axis is 0, only rows are masked. If axis is 1 or -1, only columns are masked. Synta 2 min read
- numpy.ma.MaskedArray.tolist() function - Python numpy.ma.MaskedArray.tolist() function return the data portion of the masked array as a hierarchical Python list. Syntax : numpy.ma.MaskedArray.tolist(fill_value = None) Parameters : axis : [scalar, optional] The value to use for invalid entries. Default is None. Return : [list] The Python list repr 1 min read
- numpy.ma.MaskedArray.toflex() function - Python numpy.ma.MaskedArray.toflex() function transforms a masked array into a flexible-type array. The flexible type array that is returned will have two fields: the _data field and the _mask field. The _data field stores the _data part of the array and the _mask field stores the _mask part of the array. 2 min read
- numpy.ma.clump_masked() function | Python numpy.ma.clump_masked() function returns a list of slices corresponding to the masked clumps of a 1-D array. Syntax : numpy.ma.clump_masked(arr) Parameters : arr : [ndarray] A one-dimensional masked array. Return : [list of slice] The list of slices, one for each continuous region of masked elements 1 min read
- numpy.ma.mask_or() function | Python numpy.ma.mask_or() function combine two masks with the logical_or operator. The result may be a view on m1 or m2 if the other is nomask (i.e. False). Syntax : numpy.ma.mask_or(m1, m2, copy = False, shrink = True) Parameters : m1, m2 : [ array_like] Input masks. copy : [bool, optional] If copy is Fal 2 min read
- numpy.ma.is_mask() function | Python numpy.ma.is_mask() function return True if parameter m is a valid, standard mask. This function does not check the contents of the input, only that the type is MaskType. In particular, this function returns False if the mask has a flexible dtype. Syntax : numpy.ma.is_mask(m) Parameter : m : [array_l 1 min read
- Numpy MaskedArray.var() function | Python numpy.MaskedArray.var() function is used to compute the variance along the specified axis. It returns the variance of the masked array elements, a measure of the spread of a distribution. The variance is computed for the flattened array by default, otherwise over the specified axis. Syntax : numpy.m 3 min read