numpy.trim_zeros

numpy.trim_zeros(filt, trim='fb')

Trim the leading and trailing zeros from a 1D array.

Parameters:

filt : array_like

Input array.

trim : string, optional

A string with ‘f’ representing trim from front and ‘b’ to trim from back.

Examples

>>> a = np.array((0, 0, 0, 1, 2, 3, 2, 1, 0))
>>> np.trim_zeros(a)
array([1, 2, 3, 2, 1])

Previous topic

numpy.resize

Next topic

numpy.unique

This Page

Quick search