MCPcopy Create free account
hub / github.com/numpy/numpy / compress

Method compress

numpy/ma/core.py:3893–3963  ·  view source on GitHub ↗

Return `a` where condition is ``True``. If condition is a `~ma.MaskedArray`, missing values are considered as ``False``. Parameters ---------- condition : var Boolean 1-d array selecting which entries to return. If len(condition)

(self, condition, axis=None, out=None)

Source from the content-addressed store, hash-verified

3891 return data
3892
3893 def compress(self, condition, axis=None, out=None):
3894 """
3895 Return `a` where condition is ``True``.
3896
3897 If condition is a `~ma.MaskedArray`, missing values are considered
3898 as ``False``.
3899
3900 Parameters
3901 ----------
3902 condition : var
3903 Boolean 1-d array selecting which entries to return. If len(condition)
3904 is less than the size of a along the axis, then output is truncated
3905 to length of condition array.
3906 axis : {None, int}, optional
3907 Axis along which the operation must be performed.
3908 out : {None, ndarray}, optional
3909 Alternative output array in which to place the result. It must have
3910 the same shape as the expected output but the type will be cast if
3911 necessary.
3912
3913 Returns
3914 -------
3915 result : MaskedArray
3916 A :class:`~ma.MaskedArray` object.
3917
3918 Notes
3919 -----
3920 Please note the difference with :meth:`compressed` !
3921 The output of :meth:`compress` has a mask, the output of
3922 :meth:`compressed` does not.
3923
3924 Examples
3925 --------
3926 >>> x = np.ma.array([[1,2,3],[4,5,6],[7,8,9]], mask=[0] + [1,0]*4)
3927 >>> x
3928 masked_array(
3929 data=[[1, --, 3],
3930 [--, 5, --],
3931 [7, --, 9]],
3932 mask=[[False, True, False],
3933 [ True, False, True],
3934 [False, True, False]],
3935 fill_value=999999)
3936 >>> x.compress([1, 0, 1])
3937 masked_array(data=[1, 3],
3938 mask=[False, False],
3939 fill_value=999999)
3940
3941 >>> x.compress([1, 0, 1], axis=1)
3942 masked_array(
3943 data=[[1, 3],
3944 [--, --],
3945 [7, 9]],
3946 mask=[[False, False],
3947 [ True, True],
3948 [False, False]],
3949 fill_value=999999)
3950

Callers 15

test_attributesMethod · 0.80
test_compressMethod · 0.80
test_axisMethod · 0.80
test_truncateMethod · 0.80
test_flattenMethod · 0.80
test_compressMethod · 0.80
test_small_largeMethod · 0.80
ndarray_misc.pyFile · 0.80
fromnumeric.pyFile · 0.80
compressedMethod · 0.80
test_testArrayMethodsMethod · 0.80

Calls 2

_update_fromMethod · 0.80
viewMethod · 0.45

Tested by 12

test_attributesMethod · 0.64
test_compressMethod · 0.64
test_axisMethod · 0.64
test_truncateMethod · 0.64
test_flattenMethod · 0.64
test_compressMethod · 0.64
test_small_largeMethod · 0.64
test_testArrayMethodsMethod · 0.64
test_generic_methodsMethod · 0.64
test_compressMethod · 0.64
test_compressMethod · 0.64