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

Function compress_rowcols

numpy/ma/extras.py:866–918  ·  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

864
865
866def compress_rowcols(x, axis=None):
867 """
868 Suppress the rows and/or columns of a 2-D array that contain
869 masked values.
870
871 The suppression behavior is selected with the `axis` parameter.
872
873 - If axis is None, both rows and columns are suppressed.
874 - If axis is 0, only rows are suppressed.
875 - If axis is 1 or -1, only columns are suppressed.
876
877 Parameters
878 ----------
879 x : array_like, MaskedArray
880 The array to operate on. If not a MaskedArray instance (or if no array
881 elements are masked), `x` is interpreted as a MaskedArray with
882 `mask` set to `nomask`. Must be a 2D array.
883 axis : int, optional
884 Axis along which to perform the operation. Default is None.
885
886 Returns
887 -------
888 compressed_array : ndarray
889 The compressed array.
890
891 Examples
892 --------
893 >>> x = np.ma.array(np.arange(9).reshape(3, 3), mask=[[1, 0, 0],
894 ... [1, 0, 0],
895 ... [0, 0, 0]])
896 >>> x
897 masked_array(
898 data=[[--, 1, 2],
899 [--, 4, 5],
900 [6, 7, 8]],
901 mask=[[ True, False, False],
902 [ True, False, False],
903 [False, False, False]],
904 fill_value=999999)
905
906 >>> np.ma.compress_rowcols(x)
907 array([[7, 8]])
908 >>> np.ma.compress_rowcols(x, 0)
909 array([[6, 7, 8]])
910 >>> np.ma.compress_rowcols(x, 1)
911 array([[1, 2],
912 [4, 5],
913 [7, 8]])
914
915 """
916 if asarray(x).ndim != 2:
917 raise NotImplementedError("compress_rowcols works for 2D arrays only.")
918 return compress_nd(x, axis=axis)
919
920
921def 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