tf.linalg.tensor_diag_part
Stay organized with collections
Save and categorize content based on your preferences.
Returns the diagonal part of the tensor.
tf.linalg.tensor_diag_part(
input, name=None
)
This operation returns a tensor with the diagonal
part
of the input
. The diagonal
part is computed as follows:
Assume input
has dimensions [D1,..., Dk, D1,..., Dk]
, then the output is a
tensor of rank k
with dimensions [D1,..., Dk]
where:
diagonal[i1,..., ik] = input[i1, ..., ik, i1,..., ik]
.
For a rank 2 tensor, linalg.diag_part
and linalg.tensor_diag_part
produce the same result. For rank 3 and higher, linalg.diag_part extracts
the diagonal of each inner-most matrix in the tensor. An example where
they differ is given below.
x = [[[[1111,1112],[1121,1122]],
[[1211,1212],[1221,1222]]],
[[[2111, 2112], [2121, 2122]],
[[2211, 2212], [2221, 2222]]]
]
tf.linalg.tensor_diag_part(x)
<tf.Tensor: shape=(2, 2), dtype=int32, numpy=
array([[1111, 1212],
[2121, 2222]], dtype=int32)>
tf.linalg.diag_part(x).shape
TensorShape([2, 2, 2])
Args |
input
|
A Tensor with rank 2k .
|
name
|
A name for the operation (optional).
|
Returns |
A Tensor containing diagonals of input . Has the same type as input , and
rank k .
|
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-04-26 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-04-26 UTC."],[],[],null,["# tf.linalg.tensor_diag_part\n\n\u003cbr /\u003e\n\n|-------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.16.1/tensorflow/python/ops/array_ops.py#L2354-L2396) |\n\nReturns the diagonal part of the tensor.\n\n#### View aliases\n\n\n**Compat aliases for migration**\n\nSee\n[Migration guide](https://www.tensorflow.org/guide/migrate) for\nmore details.\n\n[`tf.compat.v1.diag_part`](https://www.tensorflow.org/api_docs/python/tf/linalg/tensor_diag_part)\n\n\u003cbr /\u003e\n\n tf.linalg.tensor_diag_part(\n input, name=None\n )\n\nThis operation returns a tensor with the `diagonal` part\nof the `input`. The `diagonal` part is computed as follows:\n\nAssume `input` has dimensions `[D1,..., Dk, D1,..., Dk]`, then the output is a\ntensor of rank `k` with dimensions `[D1,..., Dk]` where:\n\n`diagonal[i1,..., ik] = input[i1, ..., ik, i1,..., ik]`.\n\nFor a rank 2 tensor, [`linalg.diag_part`](../../tf/linalg/diag_part) and [`linalg.tensor_diag_part`](../../tf/linalg/tensor_diag_part)\nproduce the same result. For rank 3 and higher, linalg.diag_part extracts\nthe diagonal of each inner-most matrix in the tensor. An example where\nthey differ is given below. \n\n x = [[[[1111,1112],[1121,1122]],\n [[1211,1212],[1221,1222]]],\n [[[2111, 2112], [2121, 2122]],\n [[2211, 2212], [2221, 2222]]]\n ]\n tf.linalg.tensor_diag_part(x)\n \u003ctf.Tensor: shape=(2, 2), dtype=int32, numpy=\n array([[1111, 1212],\n [2121, 2222]], dtype=int32)\u003e\n tf.linalg.diag_part(x).shape\n TensorShape([2, 2, 2])\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|---------|--------------------------------------|\n| `input` | A `Tensor` with rank `2k`. |\n| `name` | A name for the operation (optional). |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| A Tensor containing diagonals of `input`. Has the same type as `input`, and rank `k`. ||\n\n\u003cbr /\u003e"]]