numpy.trim_zeros() in Python

The numpy.trim_zeros() trims the leading and/or trailing zeros from a 1-D array or sequence.

Syntax

Parameter

The numpy.trim_zeros() function consists of two parameters, which are as follows:

filt : This parameter represents the 1-D array Input array.

trim : It is an optional parameter which takes a string with ‘f’ representing trim from front and ‘b’ to trim from the back. Default is ‘fb’, trim zeros from both front and back of the array.

Return

This function returns the result of trimming the input. The input data type is preserved.

Example 1

Output

Pin It on Pinterest

Share This