numpy.mask_indices() function | Python (original) (raw)
Last Updated : 22 Apr, 2020
numpy.mask_indices()
function return the indices to access (n, n) arrays, given a masking function.
Syntax : numpy.mask_indices(n, mask_func, k = 0)
Parameters :
n : [int] The returned indices will be valid to access arrays of shape (n, n).
mask_func : [callable] A function whose call signature is similar to that of triu, tril.
k : [scalar] An optional argument which is passed through to mask_func.
Return : [tuple of arrays] The n arrays of indices corresponding to the locations where mask_func(np.ones((n, n)), k) is True.
Code #1 :
import
numpy as geek
gfg
=
geek.mask_indices(
3
, geek.triu)
print
(gfg)
Output :
(array([0, 0, 0, 1, 1, 2]), array([0, 1, 2, 1, 2, 2]))
Code #2 :
import
numpy as geek
gfg
=
geek.mask_indices(
3
, geek.triu,
1
)
print
(gfg)
Output :
(array([0, 0, 1]), array([1, 2, 2]))
Similar Reads
- 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.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.tril_indices() function | Python numpy.tril_indices() function return the indices for the lower-triangle of an (n, m) array. Syntax : numpy.tril_indices(n, k = 0, m = None) Parameters : n : [int] The row dimension of the arrays for which the returned indices will be valid. k : [int, optional] Diagonal offset. m : [int, optional] Th 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.make_mask() function | Python numpy.ma.make_mask() function is used to create a boolean mask from an array. This function can accept any sequence that is convertible to integers, or nomask. It does not require that contents must be 0s and 1s, values of 0 are interpreted as False, everything else as True. Return m as a boolean ma 2 min read
- numpy.ma.fix_invalid() function | Python numpy.ma.fix_invalid() function return input with invalid data masked and replaced by a fill value. Where invalid data means values of nan, inf, etc. Syntax : numpy.ma.fix_invalid(arr, mask = False, copy = True, fill_value = None) Parameter : arr : [array_like] Input array. mask : [sequence, optiona 2 min read
- 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.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 MaskedArray.masked_inside() 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 arra 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