You are viewing an older version (2.4.3). Go to latest (2.4.4)
{ } Raw JSON

bundles / numpy 2.4.3 / numpy / ma / core / compress

function

numpy.ma.core:compress

source: /numpy/ma/core.py :7059

Signature

def   compress ( self condition axis = None out = None )

Summary

Return a where condition is True.

Extended Summary

If condition is a MaskedArray, missing values are considered as False.

Parameters

condition : var

Boolean 1-d array selecting which entries to return. If len(condition) is less than the size of a along the axis, then output is truncated to length of condition array.

axis : {None, int}, optional

Axis along which the operation must be performed.

out : {None, ndarray}, optional

Alternative output array in which to place the result. It must have the same shape as the expected output but the type will be cast if necessary.

Returns

result : MaskedArray

A MaskedArray object.

Notes

Please note the difference with compressed ! The output of compress has a mask, the output of compressed does not.

Examples

import numpy as np
x = np.ma.array([[1,2,3],[4,5,6],[7,8,9]], mask=[0] + [1,0]*4)
x
x.compress([1, 0, 1])
x.compress([1, 0, 1], axis=1)

Aliases

  • numpy.ma.compress