jax.numpy.ptp
Contents
jax.numpy.ptp#
- jax.numpy.ptp(a,axis=None,out=None,keepdims=False)[source]#
Return the peak-to-peak range along a given axis.
JAX implementation of
numpy.ptp().- Parameters:
a (ArrayLike) – input array.
axis (Axis) – optional, int or sequence of ints, default=None. Axis along which therange is computed. If None, the range is computed on the flattened array.
keepdims (bool) – bool, default=False. If true, reduced axes are left in the resultwith size 1.
out (None) – Unused by JAX.
- Returns:
An array with the range of elements along specified axis of input.
- Return type:
Examples
By default,
jnp.ptpcomputes the range along all axes.>>>x=jnp.array([[1,3,5,2],...[4,6,8,1],...[7,9,3,4]])>>>jnp.ptp(x)Array(8, dtype=int32)
If
axis=1, computes the range along axis 1.>>>jnp.ptp(x,axis=1)Array([4, 7, 6], dtype=int32)
To preserve the dimensions of input, you can set
keepdims=True.>>>jnp.ptp(x,axis=1,keepdims=True)Array([[4], [7], [6]], dtype=int32)
Contents
