Find contiguous unmasked data in a masked array along the given axis. Parameters ---------- a : array_like The input array. axis : int, optional Axis along which to perform the operation. If None (default), applies to a flattened version of the array, an
(a, axis=None)
| 1894 | |
| 1895 | |
| 1896 | def notmasked_contiguous(a, axis=None): |
| 1897 | """ |
| 1898 | Find contiguous unmasked data in a masked array along the given axis. |
| 1899 | |
| 1900 | Parameters |
| 1901 | ---------- |
| 1902 | a : array_like |
| 1903 | The input array. |
| 1904 | axis : int, optional |
| 1905 | Axis along which to perform the operation. |
| 1906 | If None (default), applies to a flattened version of the array, and this |
| 1907 | is the same as `flatnotmasked_contiguous`. |
| 1908 | |
| 1909 | Returns |
| 1910 | ------- |
| 1911 | endpoints : list |
| 1912 | A list of slices (start and end indexes) of unmasked indexes |
| 1913 | in the array. |
| 1914 | |
| 1915 | If the input is 2d and axis is specified, the result is a list of lists. |
| 1916 | |
| 1917 | See Also |
| 1918 | -------- |
| 1919 | flatnotmasked_edges, flatnotmasked_contiguous, notmasked_edges |
| 1920 | clump_masked, clump_unmasked |
| 1921 | |
| 1922 | Notes |
| 1923 | ----- |
| 1924 | Only accepts 2-D arrays at most. |
| 1925 | |
| 1926 | Examples |
| 1927 | -------- |
| 1928 | >>> a = np.arange(12).reshape((3, 4)) |
| 1929 | >>> mask = np.zeros_like(a) |
| 1930 | >>> mask[1:, :-1] = 1; mask[0, 1] = 1; mask[-1, 0] = 0 |
| 1931 | >>> ma = np.ma.array(a, mask=mask) |
| 1932 | >>> ma |
| 1933 | masked_array( |
| 1934 | data=[[0, --, 2, 3], |
| 1935 | [--, --, --, 7], |
| 1936 | [8, --, --, 11]], |
| 1937 | mask=[[False, True, False, False], |
| 1938 | [ True, True, True, False], |
| 1939 | [False, True, True, False]], |
| 1940 | fill_value=999999) |
| 1941 | >>> np.array(ma[~ma.mask]) |
| 1942 | array([ 0, 2, 3, 7, 8, 11]) |
| 1943 | |
| 1944 | >>> np.ma.notmasked_contiguous(ma) |
| 1945 | [slice(0, 1, None), slice(2, 4, None), slice(7, 9, None), slice(11, 12, None)] |
| 1946 | |
| 1947 | >>> np.ma.notmasked_contiguous(ma, axis=0) |
| 1948 | [[slice(0, 1, None), slice(2, 3, None)], [], [slice(0, 1, None)], [slice(0, 3, None)]] |
| 1949 | |
| 1950 | >>> np.ma.notmasked_contiguous(ma, axis=1) |
| 1951 | [[slice(0, 1, None), slice(2, 4, None)], [slice(3, 4, None)], [slice(0, 1, None), slice(3, 4, None)]] |
| 1952 | |
| 1953 | """ |