trim_zeros#

ivy.trim_zeros(a, /, *, trim='fb')[source]#

ivy.Container instance method variant of ivy.trim_zeros. This method simply wraps the function, and so the docstring for ivy.trim_zeros also applies to this method with minimal changes.

Parameters:
  • a (1-D array) – 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.

Return type:

Array

Returns:

1-D array The result of trimming the input. The input data type is preserved.

Examples

>>> a = ivy.array([0, 0, 0, 0, 8, 3, 0, 0, 7, 1, 0])
>>> ivy.trim_zeros(a)
array([8, 3, 0, 0, 7, 1])
>>> ivy.trim_zeros(a, 'b')
array([0, 0, 0, 0, 8, 3, 0, 0, 7, 1])
>>> ivy.trim_zeros([0, 8, 3, 0, 0])
[8, 3]
Array.trim_zeros(self, /, *, trim='fb')[source]#

ivy.Array instance method variant of ivy.trim_zeros.

This method simply wraps the function, and so the docstring for ivy.trim_zeros also applies to this method with minimal changes.

Parameters:
  • self (1-D array) – 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.

Return type:

Array

Returns:

  • 1-D array

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

Examples

>>> a = ivy.array([0, 0, 0, 0, 8, 3, 0, 0, 7, 1, 0])
>>> ivy.trim_zeros(a)
array([8, 3, 0, 0, 7, 1])
>>> ivy.trim_zeros(a, 'b')
array([0, 0, 0, 0, 8, 3, 0, 0, 7, 1])
>>> ivy.trim_zeros([0, 8, 3, 0, 0])
[8, 3]
Container.trim_zeros(self, /, *, trim='fb')[source]#

ivy.Container instance method variant of ivy.trim_zeros. This method simply wraps the function, and so the docstring for ivy.trim_zeros also applies to this method with minimal changes.

Parameters:
  • self (1-D array) – 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.

Return type:

Array

Returns:

  • 1-D array

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

Examples

>>> a = ivy.array([0, 0, 0, 0, 8, 3, 0, 0, 7, 1, 0])
>>> ivy.trim_zeros(a)
array([8, 3, 0, 0, 7, 1])
>>> ivy.trim_zeros(a, 'b')
array([0, 0, 0, 0, 8, 3, 0, 0, 7, 1])
>>> ivy.trim_zeros([0, 8, 3, 0, 0])
[8, 3]