Numpy MaskedArray.compressed() function Python (original) (raw)
Last Updated : 26 Mar, 2020
numpy.MaskedArray.compressed()
function return all the non-masked data as a 1-D array.
Syntax : numpy.MaskedArray.compressed(self)
Return : [ndarray] A new ndarray holding the non-masked data is returned.
Code #1 :
import
numpy as geek
import
numpy.ma as ma
arr
=
geek.ma.array(geek.arange(
10
), mask
=
[
0
]
*
6
+
[
1
]
*
4
)
gfg
=
arr.compressed()
print
(gfg)
Output :
[0 1 2 3 4 5]
Code #2 :
import
numpy as geek
import
numpy.ma as ma
arr
=
geek.ma.array(geek.arange(
7
), mask
=
[
0
]
*
4
+
[
1
]
*
3
)
gfg
=
arr.compressed()
print
(gfg)
Output :
[0 1 2 3]
Similar Reads
- 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.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.astype() 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.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.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
- 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.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 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.ma.MaskedArray.count() function - Python 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 N 2 min read