This is a pre-release version (2.5.0.dev0+git20251130.2de293a). Go to latest (2.4.4)
{ } Raw JSON

bundles / numpy 2.5.0.dev0+git20251130.2de293a / numpy / ma / extras / compress_nd

function

numpy.ma.extras:compress_nd

source: build-install/usr/lib/python3.14/site-packages/numpy/ma/extras.py :841

Signature

def   compress_nd ( x axis = None )

Summary

Suppress slices from multiple dimensions which contain masked values.

Parameters

x : array_like, MaskedArray

The array to operate on. If not a MaskedArray instance (or if no array elements are masked), x is interpreted as a MaskedArray with mask set to nomask.

axis : tuple of ints or int, optional

Which dimensions to suppress slices from can be configured with this parameter. - If axis is a tuple of ints, those are the axes to suppress slices from. - If axis is an int, then that is the only axis to suppress slices from. - If axis is None, all axis are selected.

Returns

compress_array : ndarray

The compressed array.

Examples

import numpy as np
arr = [[1, 2], [3, 4]]
mask = [[0, 1], [0, 0]]
x = np.ma.array(arr, mask=mask)
np.ma.compress_nd(x, axis=0)
np.ma.compress_nd(x, axis=1)
np.ma.compress_nd(x)

Aliases

  • numpy.ma.compress_nd