tf.keras.ops.trace
Stay organized with collections
Save and categorize content based on your preferences.
Return the sum along diagonals of the tensor.
tf.keras.ops.trace(
x, offset=0, axis1=0, axis2=1
)
If x
is 2-D, the sum along its diagonal with the given offset is
returned, i.e., the sum of elements x[i, i+offset]
for all i
.
If a has more than two dimensions, then the axes specified by axis1
and axis2
are used to determine the 2-D sub-arrays whose traces are
returned.
The shape of the resulting tensor is the same as that of x
with axis1
and axis2
removed.
Args |
x
|
Input tensor.
|
offset
|
Offset of the diagonal from the main diagonal. Can be
both positive and negative. Defaults to 0 .
|
axis1
|
Axis to be used as the first axis of the 2-D sub-arrays.
Defaults to 0 .(first axis).
|
axis2
|
Axis to be used as the second axis of the 2-D sub-arrays.
Defaults to 1 (second axis).
|
Returns |
If x is 2-D, the sum of the diagonal is returned. If x has
larger dimensions, then a tensor of sums along diagonals is
returned.
|
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."],[],[]]