Find contiguous unmasked data in a masked array. Parameters ---------- a : array_like The input array. Returns ------- slice_list : list A sorted sequence of `slice` objects (start index, end index). .. versionchanged:: 1.15.0 Now r
(a)
| 1837 | |
| 1838 | |
| 1839 | def flatnotmasked_contiguous(a): |
| 1840 | """ |
| 1841 | Find contiguous unmasked data in a masked array. |
| 1842 | |
| 1843 | Parameters |
| 1844 | ---------- |
| 1845 | a : array_like |
| 1846 | The input array. |
| 1847 | |
| 1848 | Returns |
| 1849 | ------- |
| 1850 | slice_list : list |
| 1851 | A sorted sequence of `slice` objects (start index, end index). |
| 1852 | |
| 1853 | .. versionchanged:: 1.15.0 |
| 1854 | Now returns an empty list instead of None for a fully masked array |
| 1855 | |
| 1856 | See Also |
| 1857 | -------- |
| 1858 | flatnotmasked_edges, notmasked_contiguous, notmasked_edges |
| 1859 | clump_masked, clump_unmasked |
| 1860 | |
| 1861 | Notes |
| 1862 | ----- |
| 1863 | Only accepts 2-D arrays at most. |
| 1864 | |
| 1865 | Examples |
| 1866 | -------- |
| 1867 | >>> a = np.ma.arange(10) |
| 1868 | >>> np.ma.flatnotmasked_contiguous(a) |
| 1869 | [slice(0, 10, None)] |
| 1870 | |
| 1871 | >>> mask = (a < 3) | (a > 8) | (a == 5) |
| 1872 | >>> a[mask] = np.ma.masked |
| 1873 | >>> np.array(a[~a.mask]) |
| 1874 | array([3, 4, 6, 7, 8]) |
| 1875 | |
| 1876 | >>> np.ma.flatnotmasked_contiguous(a) |
| 1877 | [slice(3, 5, None), slice(6, 9, None)] |
| 1878 | >>> a[:] = np.ma.masked |
| 1879 | >>> np.ma.flatnotmasked_contiguous(a) |
| 1880 | [] |
| 1881 | |
| 1882 | """ |
| 1883 | m = getmask(a) |
| 1884 | if m is nomask: |
| 1885 | return [slice(0, a.size)] |
| 1886 | i = 0 |
| 1887 | result = [] |
| 1888 | for (k, g) in itertools.groupby(m.ravel()): |
| 1889 | n = len(list(g)) |
| 1890 | if not k: |
| 1891 | result.append(slice(i, i + n)) |
| 1892 | i += n |
| 1893 | return result |
| 1894 | |
| 1895 | |
| 1896 | def notmasked_contiguous(a, axis=None): |