Skip to content

Commit

Permalink
Merge pull request #23540 from rajasekharporeddy:testbranch2
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 673007161
  • Loading branch information
jax authors committed Sep 10, 2024
2 parents 9fa0164 + c5bc241 commit a8b68c2
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion jax/_src/numpy/lax_numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -6375,8 +6375,28 @@ def diagflat(v: ArrayLike, k: int = 0) -> Array:
return res


@util.implements(np.trim_zeros)
def trim_zeros(filt, trim='fb'):
"""Trim leading and/or trailing zeros of the input array.
JAX implementation of :func:`numpy.trim_zeros`.
Args:
filt: input array. Must have ``filt.ndim == 1``.
trim: string, optional, default = ``fb``. Specifies from which end the input
is trimmed.
- ``f`` - trims only the leading zeros.
- ``b`` - trims only the trailing zeros.
- ``fb`` - trims both leading and trailing zeros.
Returns:
An array containig the trimmed input with same dtype as ``filt``.
Examples:
>>> x = jnp.array([0, 0, 2, 0, 1, 4, 3, 0, 0, 0])
>>> jnp.trim_zeros(x)
Array([2, 0, 1, 4, 3], dtype=int32)
"""
filt = core.concrete_or_error(asarray, filt,
"Error arose in the `filt` argument of trim_zeros()")
nz = (filt == 0)
Expand Down

0 comments on commit a8b68c2

Please sign in to comment.