numpy.ma.notmasked_edges() function | Python (original) (raw)
Last Updated : 22 Apr, 2020
numpy.ma.notmasked_edges()
function find the indices of the first and last unmasked values along an axis.
Return None, if all values are masked. Otherwise, return a list of two tuples, corresponding to the indices of the first and last unmasked values respectively.
Syntax : numpy.ma.notmasked_edges(arr, axis = None)
Parameters :
arr : [array_like] The input array.
axis : [int, optional] Axis along which to perform the operation. Default is None.Return : [ ndarray or list] An array of start and end indexes if there are any masked data in the array. If there are no masked data in the array, edges is a list of the first and last index.
Code #1 :
import
numpy as geek
import
numpy.ma as ma
arr
=
geek.arange(
12
).reshape((
3
,
4
))
gfg
=
geek.ma.notmasked_edges(arr)
print
(gfg)
Output :
[ 0, 11]
Code #2 :
import
numpy as geek
import
numpy.ma as ma
arr
=
geek.arange(
12
).reshape((
3
,
4
))
m
=
geek.zeros_like(arr)
m[
1
:,
1
:]
=
1
am
=
geek.ma.array(arr, mask
=
m)
gfg
=
geek.ma.notmasked_edges(am)
print
(gfg)
Output :
[0, 8]
Similar Reads
- numpy.ma.notmasked_contiguous function | Python numpy.ma.notmasked_contiguous() function find contiguous unmasked data in a masked array along the given axis. Syntax : numpy.ma.notmasked_contiguous(arr, axis = None) Parameters : arr : [array_like] The input array. axis : [int, optional] Axis along which to perform the operation. Default is None. 2 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_cols() function | Python In thisnumpy.ma.mask_cols() function, mask columns of a 2D array that contain masked values. This function is a shortcut to mask_rowcols with axis equal to 1. Syntax : numpy.ma.mask_cols(arr, axis = None) Parameters : arr : [array_like, MaskedArray] The array to mask. axis : [int, optional] Axis alo 1 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.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.ma.masked_all_like() function | Python numpy.ma.masked_all_like() function return an empty masked array of the same shape and dtype as the array arr, where all the data are masked. Syntax : numpy.ma.masked_all_like(arr) Parameter : arr : [ndarray] An array describing the shape and dtype of the required MaskedArray. Return : [MaskedArray] 1 min read
- numpy.ma.masked_values() function | Python 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, c 2 min read
- Numpy MaskedArray.average() function | Python numpy.MaskedArray.average() function is used to return the weighted average of array over the given axis. Syntax : numpy.ma.average(arr, axis=None, weights=None, returned=False) Parameters: arr :[ array_like] Input masked array whose data to be averaged. Masked entries are not taken into account in 3 min read