Open In App

numpy.ma.compress_rowcols() function in Python

Last Updated : 12 Nov, 2020
Comments
Improve
Suggest changes
Like Article
Like
Report

numpy.ma.compress_rowcols() function suppresses rows and columns that contain masked values in a 2-D array. 
The suppression behavior is selected with the axis parameter: 

  • If axis is None, both rows and columns are suppressed.
  • If axis is 0, only rows are suppressed.
  • If axis is 1 or -1, only columns are suppressed.

Syntax : numpy.ma.compress_rowcols(arr, axis = None) 

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. 
axis : [int, optional] Axis along which to perform the operation. Default is None. 

Return : Return the compressed array.

Code #1: 

Python3
# Python program explaining
# numpy.ma.compress_rowcols() function

# importing numpy as geek
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_rowcols(arr)

print(gfg)

Output: 

[[4 5]]

Code #2: 

Python3
# Python program explaining
# numpy.ma.compress_rowcols() function

# importing numpy as geek
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_rowcols(arr, 1)

print(gfg)

Output:

[[1 2]
 [4 5]]

Practice Tags :

Similar Reads

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy