MCPcopy Index your code
hub / github.com/numpy/numpy / compress_rowcols

Function compress_rowcols

numpy/ma/extras.py:899–952  ·  view source on GitHub ↗

Suppress the rows and/or columns of a 2-D array that contain masked values. 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

(x, axis=None)

Source from the content-addressed store, hash-verified

897
898
899def compress_rowcols(x, axis=None):
900 """
901 Suppress the rows and/or columns of a 2-D array that contain
902 masked values.
903
904 The suppression behavior is selected with the `axis` parameter.
905
906 - If axis is None, both rows and columns are suppressed.
907 - If axis is 0, only rows are suppressed.
908 - If axis is 1 or -1, only columns are suppressed.
909
910 Parameters
911 ----------
912 x : array_like, MaskedArray
913 The array to operate on. If not a MaskedArray instance (or if no array
914 elements are masked), `x` is interpreted as a MaskedArray with
915 `mask` set to `nomask`. Must be a 2D array.
916 axis : int, optional
917 Axis along which to perform the operation. Default is None.
918
919 Returns
920 -------
921 compressed_array : ndarray
922 The compressed array.
923
924 Examples
925 --------
926 >>> import numpy as np
927 >>> x = np.ma.array(np.arange(9).reshape(3, 3), mask=[[1, 0, 0],
928 ... [1, 0, 0],
929 ... [0, 0, 0]])
930 >>> x
931 masked_array(
932 data=[[--, 1, 2],
933 [--, 4, 5],
934 [6, 7, 8]],
935 mask=[[ True, False, False],
936 [ True, False, False],
937 [False, False, False]],
938 fill_value=999999)
939
940 >>> np.ma.compress_rowcols(x)
941 array([[7, 8]])
942 >>> np.ma.compress_rowcols(x, 0)
943 array([[6, 7, 8]])
944 >>> np.ma.compress_rowcols(x, 1)
945 array([[1, 2],
946 [4, 5],
947 [7, 8]])
948
949 """
950 if asarray(x).ndim != 2:
951 raise NotImplementedError("compress_rowcols works for 2D arrays only.")
952 return compress_nd(x, axis=axis)
953
954
955def compress_rows(a):

Callers 3

test_compress_rowcolsMethod · 0.90
compress_rowsFunction · 0.85
compress_colsFunction · 0.85

Calls 2

compress_ndFunction · 0.85
asarrayFunction · 0.70

Tested by 1

test_compress_rowcolsMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…