numpy.ma.compress_cols() function in Python
Last Updated :
12 Nov, 2020
Prerequisite: numpy
This numpy inbuilt function suppresses whole columns that contain masked values in a 2-D array.
Syntax: numpy.ma.compress_cols(arr)
Parameters :
arr : [array_like, MaskedArray]
- This parameter holds the array to operate on.
- The array must be a 2D array.
- If no array elements are masked, arr is interpreted as a MaskedArray with mask set to nomask.
Return : Returns the compressed array.
Below is the Implementation of the above function.
Example 1:
Python3
import numpy as geek
arr = geek.ma.array(geek.arange( 6 ).reshape( 2 , 3 ),
mask = [[ 1 , 0 , 0 ], [ 0 , 0 , 0 ]])
gfg = geek.ma.compress_cols(arr)
print (gfg)
|
Output :
[[1 2]
[4 5]]
Example 2:
Python3
import numpy as geek
arr = geek.ma.array(geek.arange( 9 ).reshape( 3 , 3 ), mask = [
[ 1 , 0 , 0 ], [ 1 , 0 , 0 ], [ 0 , 0 , 0 ]])
gfg = geek.ma.compress_cols(arr)
print (gfg)
|
Output :
[[1 2]
[4 5]
[7 8]]
Share your thoughts in the comments
Please Login to comment...