tf.keras.ops.diff
Stay organized with collections
Save and categorize content based on your preferences.
Calculate the n-th discrete difference along the given axis.
tf.keras.ops.diff(
a, n=1, axis=-1
)
The first difference is given by out[i] = a[i+1] - a[i]
along
the given axis, higher differences are calculated by using diff
recursively.
Args |
a
|
Input tensor.
|
n
|
The number of times values are differenced. Defaults to 1 .
|
axis
|
Axis to compute discrete difference(s) along.
Defaults to -1 .(last axis).
|
Returns |
Tensor of diagonals.
|
Examples:
from keras.src import ops
x = ops.convert_to_tensor([1, 2, 4, 7, 0])
ops.diff(x)
array([ 1, 2, 3, -7])
ops.diff(x, n=2)
array([ 1, 1, -10])
x = ops.convert_to_tensor([[1, 3, 6, 10], [0, 5, 6, 8]])
ops.diff(x)
array([[2, 3, 4],
[5, 1, 2]])
ops.diff(x, axis=0)
array([[-1, 2, 0, -2]])
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 2024-06-07 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 2024-06-07 UTC."],[],[]]