numpy.ma.MaskedArray.count() function Python (original) (raw)
Last Updated : 05 May, 2020
numpy.ma.MaskedArray.count()
function count the non-masked elements of the array along the given axis.
Syntax : numpy.ma.MaskedArray.count(self, axis=None, keepdims = no value)
Parameters :
axis : [None or int or tuple of ints, optional] Axis along which the count is performed. The default axis is None, performs the count over all the dimensions of the input array. axis may be negative, in which case it counts from the last to the first axis.
keepdims : [bool, optional] If this is set to True, the axis which is reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the array.Return : [ndarray or scalar] An array with the same shape as the input array, with the specified axis removed. If the array is a 0-d array, or if axis is None, a scalar is returned.
Code #1 :
import
numpy as geek
import
numpy.ma as ma
arr
=
ma.arange(
6
).reshape((
2
,
3
))
arr[
1
, :]
=
ma.masked
gfg
=
arr.count(axis
=
0
)
print
(gfg)
Output :
[1 1 1]
Code #2 :
import
numpy as geek
import
numpy.ma as ma
arr
=
ma.arange(
6
).reshape((
2
,
3
))
arr[
1
, :]
=
ma.masked
gfg
=
arr.count()
print
(gfg)
Output :
3
Similar Reads
- 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 arra 3 min read
- Numpy MaskedArray.conjugate() function | Python numpy.MaskedArray.conjugate() function is used to return the complex conjugate, element-wise.The conjugate of a complex number is obtained by changing the sign of its imaginary part. Syntax : numpy.ma.conjugate(arr, out=None, where=True, casting='same_kind', order='K', dtype=None, subok=True)Paramet 2 min read
- Numpy MaskedArray.cumsum() function | Python numpy.MaskedArray.cumsum() Return the cumulative sum of the masked array elements over the given axis.Masked values are set to 0 internally during the computation. However, their position is saved, and the result will be masked at the same locations. Syntax : numpy.ma.cumsum(axis=None, dtype=None, o 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 arra 2 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 arra 3 min read
- Numpy MaskedArray.cumprod() function | Python numpy.MaskedArray.cumprod() Return the cumulative product of the masked array elements over the given axis.Masked values are set to 1 internally during the computation. However, their position is saved, and the result will be masked at the same locations. Syntax : numpy.ma.cumprod(axis=None, dtype=N 3 min read
- Numpy MaskedArray.masked_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 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 arr 3 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.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