MCPcopy
hub / github.com/numpy/numpy / _arg_trim_zeros

Function _arg_trim_zeros

numpy/lib/_function_base_impl.py:1908–1944  ·  view source on GitHub ↗

Return indices of the first and last non-zero element. Parameters ---------- filt : array_like Input array. Returns ------- start, stop : ndarray Two arrays containing the indices of the first and last non-zero element in each dimension. See als

(filt)

Source from the content-addressed store, hash-verified

1906
1907
1908def _arg_trim_zeros(filt):
1909 """Return indices of the first and last non-zero element.
1910
1911 Parameters
1912 ----------
1913 filt : array_like
1914 Input array.
1915
1916 Returns
1917 -------
1918 start, stop : ndarray
1919 Two arrays containing the indices of the first and last non-zero
1920 element in each dimension.
1921
1922 See also
1923 --------
1924 trim_zeros
1925
1926 Examples
1927 --------
1928 >>> import numpy as np
1929 >>> _arg_trim_zeros(np.array([0, 0, 1, 1, 0]))
1930 (array([2]), array([3]))
1931 """
1932 nonzero = (
1933 np.argwhere(filt)
1934 if filt.dtype != np.object_
1935 # Historically, `trim_zeros` treats `None` in an object array
1936 # as non-zero while argwhere doesn't, account for that
1937 else np.argwhere(filt != 0)
1938 )
1939 if nonzero.size == 0:
1940 start = stop = np.array([], dtype=np.intp)
1941 else:
1942 start = nonzero.min(axis=0)
1943 stop = nonzero.max(axis=0)
1944 return start, stop
1945
1946
1947def _trim_zeros(filt, trim=None, axis=None):

Callers 1

trim_zerosFunction · 0.85

Calls 2

minMethod · 0.45
maxMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…