tf.keras.ops.ptp
Stay organized with collections
Save and categorize content based on your preferences.
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.
Args |
x
|
Input tensor.
|
axis
|
Axis or axes along which the peak-to-peak value is computed.
The default, axis=None, will compute the peak-to-peak value
over all elements in the input tensor.
|
keepdims
|
If this is set to True, the axes which are reduced
are left in the result as dimensions with size one.
|
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 elements
keras.ops.ptp(x)
5.0
# Peak-to-peak along axis 1
keras.ops.ptp(x, axis=1)
array([2., 5.], dtype=float32)
# Peak-to-peak over multiple axes
x = keras.ops.reshape(x, (1, 2, 3))
keras.ops.ptp(x, axis=(1, 2))
array([5.], dtype=float32)
# Keep reduced dimensions
keras.ops.ptp(x, axis=2, keepdims=True)
array([[[2.],
[5.]]], dtype=float32)
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates. Some content is licensed under the numpy license.
Last updated 2026-10-31 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2026-10-31 UTC."],[],[]]