numpy.trim_zeros(filt, trim='fb')
[source]
Trim the leading and/or trailing zeros from a 1-D array or sequence.
Parameters: |
|
---|---|
Returns: |
|
>>> a = np.array((0, 0, 0, 1, 2, 3, 0, 2, 1, 0)) >>> np.trim_zeros(a) array([1, 2, 3, 0, 2, 1])
>>> np.trim_zeros(a, 'b') array([0, 0, 0, ..., 0, 2, 1])
The input data type is preserved, list/tuple in means list/tuple out.
>>> np.trim_zeros([0, 1, 2, 0]) [1, 2]
© 2005–2019 NumPy Developers
Licensed under the 3-clause BSD License.
https://docs.scipy.org/doc/numpy-1.17.0/reference/generated/numpy.trim_zeros.html