View source on GitHub
|
Return the peak-to-peak (max - min) value of tensor elements over a given axis.
tf.keras.ops.ptp(
x, axis=None, keepdims=False
)
The peak-to-peak value is defined as the difference between the maximum and minimum values along the specified axis.
Returns | |
|---|---|
A tensor containing the peak-to-peak values of x over the
given axis or axes.
|
Examples:
x = keras.ops.array([[1., 3., 2.],[4., 0., 5.]])
# Peak-to-peak over all elementskeras.ops.ptp(x)5.0
# Peak-to-peak along axis 1keras.ops.ptp(x, axis=1)array([2., 5.], dtype=float32)
# Peak-to-peak over multiple axesx = keras.ops.reshape(x, (1, 2, 3))keras.ops.ptp(x, axis=(1, 2))array([5.], dtype=float32)
# Keep reduced dimensionskeras.ops.ptp(x, axis=2, keepdims=True)array([[[2.],[5.]]], dtype=float32)
View source on GitHub