numpy 1.22.4 Pypi GitHub Homepage
Other Docs
ParametersReturns
trim_zeros(filt, trim='fb')

Parameters

filt : 1-D array or sequence

Input array.

trim : str, optional

A string with 'f' representing trim from front and 'b' to trim from back. Default is 'fb', trim zeros from both front and back of the array.

Returns

trimmed : 1-D array or sequence

The result of trimming the input. The input data type is preserved.

Trim the leading and/or trailing zeros from a 1-D array or sequence.

Examples

>>> 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]
See :

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


GitHub : /numpy/lib/function_base.py#1775
type: <class 'function'>
Commit: