Organízate con las colecciones
Guarda y clasifica el contenido según tus preferencias.
flujo tensor:: operaciones:: MatrizDiagPartV3
#include <array_ops.h>
Devuelve la parte diagonal por lotes de un tensor por lotes.
Resumen
Devuelve un tensor con las diagonales k[0]
-ésima a k[1]
-ésima de la input
por lotes.
Supongamos que input
tiene r
dimensiones [I, J, ..., L, M, N]
. Sea max_diag_len
la longitud máxima entre todas las diagonales a extraer, max_diag_len = min(M + min(k[1], 0), N + min(-k[0], 0))
Sea num_diags
el número de diagonales a extraer extraer, num_diags = k[1] - k[0] + 1
.
Si num_diags == 1
, el tensor de salida es de rango r - 1
con forma [I, J, ..., L, max_diag_len]
y valores:
diagonal[i, j, ..., l, n]
= input[i, j, ..., l, n+y, n+x] ; if 0 <= n+y < M and 0 <= n+x < N,
padding_value ; otherwise.
donde
y = max(-k[1], 0)
,
x = max(k[1], 0)
.
De lo contrario, el tensor de salida tiene rango r
con dimensiones [I, J, ..., L, num_diags, max_diag_len]
con valores:
diagonal[i, j, ..., l, m, n]
= input[i, j, ..., l, n+y, n+x] ; if 0 <= n+y < M and 0 <= n+x < N,
padding_value ; otherwise.
donde
d = k[1] - m
,
y = max(-d, 0) - offset
y
x = max(d, 0) - offset
.
offset
es cero excepto cuando la alineación de la diagonal es hacia la derecha.
offset = max_diag_len - diag_len(d) ; if (`align` in {RIGHT_LEFT, RIGHT_RIGHT}
and `d >= 0`) or
(`align` in {LEFT_RIGHT, RIGHT_RIGHT}
and `d <= 0`)
0 ; otherwise
donde
diag_len(d) = min(cols - max(d, 0), rows + min(d, 0))
.
La entrada debe ser al menos una matriz.
Por ejemplo:
input = np.array([[[1, 2, 3, 4], # Input shape: (2, 3, 4)
[5, 6, 7, 8],
[9, 8, 7, 6]],
[[5, 4, 3, 2],
[1, 2, 3, 4],
[5, 6, 7, 8]]])
# A main diagonal from each batch.
tf.matrix_diag_part(input) ==> [[1, 6, 7], # Output shape: (2, 3)
[5, 2, 7]]
# A superdiagonal from each batch.
tf.matrix_diag_part(input, k = 1)
==> [[2, 7, 6], # Output shape: (2, 3)
[4, 3, 8]]
# A band from each batch.
tf.matrix_diag_part(input, k = (-1, 2))
==> [[[0, 3, 8], # Output shape: (2, 4, 3)
[2, 7, 6],
[1, 6, 7],
[5, 8, 0]],
[[0, 3, 4],
[4, 3, 8],
[5, 2, 7],
[1, 6, 0]]]
# LEFT_RIGHT alignment.
tf.matrix_diag_part(input, k = (-1, 2), align="LEFT_RIGHT")
==> [[[3, 8, 0], # Output shape: (2, 4, 3)
[2, 7, 6],
[1, 6, 7],
[0, 5, 8]],
[[3, 4, 0],
[4, 3, 8],
[5, 2, 7],
[0, 1, 6]]]
# max_diag_len can be shorter than the main diagonal.
tf.matrix_diag_part(input, k = (-2, -1))
==> [[[5, 8],
[9, 0]],
[[1, 6],
[5, 0]]]
# padding_value = 9
tf.matrix_diag_part(input, k = (1, 3), padding_value = 9)
==> [[[9, 9, 4], # Output shape: (2, 3, 3)
[9, 3, 8],
[2, 7, 6]],
[[9, 9, 2],
[9, 3, 4],
[4, 3, 8]]]
Arguments:
- scope: A Scope object
- input: Rank
r
tensor where r >= 2
.
- k: Diagonal offset(s). Positive value means superdiagonal, 0 refers to the main diagonal, and negative value means subdiagonals.
k
can be a single integer (for a single diagonal) or a pair of integers specifying the low and high ends of a matrix band. k[0]
must not be larger than k[1]
.
- padding_value: The value to fill the area outside the specified diagonal band with. Default is 0.
Optional attributes (see Attrs
):
- align: Some diagonals are shorter than
max_diag_len
and need to be padded. align
is a string specifying how superdiagonals and subdiagonals should be aligned, respectively. There are four possible alignments: "RIGHT_LEFT" (default), "LEFT_RIGHT", "LEFT_LEFT", and "RIGHT_RIGHT". "RIGHT_LEFT" aligns superdiagonals to the right (left-pads the row) and subdiagonals to the left (right-pads the row). It is the packing format LAPACK uses. cuSPARSE uses "LEFT_RIGHT", which is the opposite alignment.
Returns:
Output
: The extracted diagonal(s).
Public static functions
|
Align(StringPiece x)
|
|
Public attributes
Funciones públicas
nodo
::tensorflow::Node * node() const
operator::tensorflow::Input() const
operador::tensorflow::Salida
operator::tensorflow::Output() const
Funciones estáticas públicas
Alinear
Attrs Align(
StringPiece x
)
A menos que se indique lo contrario, el contenido de esta página está sujeto a la licencia Reconocimiento 4.0 de Creative Commons y las muestras de código están sujetas a la licencia Apache 2.0. Para obtener más información, consulta las políticas del sitio web de Google Developers. Java es una marca registrada de Oracle o sus afiliados.
Última actualización: 2025-07-27 (UTC).
[null,null,["Última actualización: 2025-07-27 (UTC)."],[],[],null,["# tensorflow::ops::MatrixDiagPartV3 Class Reference\n\ntensorflow::ops::MatrixDiagPartV3\n=================================\n\n`#include \u003carray_ops.h\u003e`\n\nReturns the batched diagonal part of a batched tensor.\n\nSummary\n-------\n\nReturns a tensor with the `k[0]`-th to `k[1]`-th diagonals of the batched `input`.\n\nAssume `input` has `r` dimensions `[I, J, ..., L, M, N]`. Let `max_diag_len` be the maximum length among all diagonals to be extracted, `max_diag_len = min(M + min(k[1], 0), N + min(-k[0], 0))` Let `num_diags` be the number of diagonals to extract, `num_diags = k[1] - k[0] + 1`.\n\nIf `num_diags == 1`, the output tensor is of rank `r - 1` with shape `[I, J, ..., L, max_diag_len]` and values:\n\n\u003cbr /\u003e\n\n```scdoc\ndiagonal[i, j, ..., l, n]\n = input[i, j, ..., l, n+y, n+x] ; if 0 \u003c= n+y \u003c M and 0 \u003c= n+x \u003c N,\n padding_value ; otherwise.\n```\nwhere `y = max(-k[1], 0)`, `x = max(k[1], 0)`.\n\n\u003cbr /\u003e\n\nOtherwise, the output tensor has rank `r` with dimensions `[I, J, ..., L, num_diags, max_diag_len]` with values:\n\n\u003cbr /\u003e\n\n```scdoc\ndiagonal[i, j, ..., l, m, n]\n = input[i, j, ..., l, n+y, n+x] ; if 0 \u003c= n+y \u003c M and 0 \u003c= n+x \u003c N,\n padding_value ; otherwise.\n```\nwhere `d = k[1] - m`, `y = max(-d, 0) - offset`, and `x = max(d, 0) - offset`.\n\n\u003cbr /\u003e\n\n`offset` is zero except when the alignment of the diagonal is to the right. \n\n```mysql\noffset = max_diag_len - diag_len(d) ; if (`align` in {RIGHT_LEFT, RIGHT_RIGHT}\n and `d \u003e= 0`) or\n (`align` in {LEFT_RIGHT, RIGHT_RIGHT}\n and `d \u003c= 0`)\n 0 ; otherwise\n```\nwhere `diag_len(d) = min(cols - max(d, 0), rows + min(d, 0))`.\n\n\u003cbr /\u003e\n\nThe input must be at least a matrix.\n\nFor example:\n\n\n```text\ninput = np.array([[[1, 2, 3, 4], # Input shape: (2, 3, 4)\n [5, 6, 7, 8],\n [9, 8, 7, 6]],\n [[5, 4, 3, 2],\n [1, 2, 3, 4],\n [5, 6, 7, 8]]])\n```\n\n\u003cbr /\u003e\n\n\n```scdoc\n# A main diagonal from each batch.\ntf.matrix_diag_part(input) ==\u003e [[1, 6, 7], # Output shape: (2, 3)\n [5, 2, 7]]\n```\n\n\u003cbr /\u003e\n\n\n```scdoc\n# A superdiagonal from each batch.\ntf.matrix_diag_part(input, k = 1)\n ==\u003e [[2, 7, 6], # Output shape: (2, 3)\n [4, 3, 8]]\n```\n\n\u003cbr /\u003e\n\n\n```scdoc\n# A band from each batch.\ntf.matrix_diag_part(input, k = (-1, 2))\n ==\u003e [[[0, 3, 8], # Output shape: (2, 4, 3)\n [2, 7, 6],\n [1, 6, 7],\n [5, 8, 0]],\n [[0, 3, 4],\n [4, 3, 8],\n [5, 2, 7],\n [1, 6, 0]]]\n```\n\n\u003cbr /\u003e\n\n\n```scdoc\n# LEFT_RIGHT alignment.\ntf.matrix_diag_part(input, k = (-1, 2), align=\"LEFT_RIGHT\")\n ==\u003e [[[3, 8, 0], # Output shape: (2, 4, 3)\n [2, 7, 6],\n [1, 6, 7],\n [0, 5, 8]],\n [[3, 4, 0],\n [4, 3, 8],\n [5, 2, 7],\n [0, 1, 6]]]\n```\n\n\u003cbr /\u003e\n\n\n```scdoc\n# max_diag_len can be shorter than the main diagonal.\ntf.matrix_diag_part(input, k = (-2, -1))\n ==\u003e [[[5, 8],\n [9, 0]],\n [[1, 6],\n [5, 0]]]\n```\n\n\u003cbr /\u003e\n\n\n```scdoc\n# padding_value = 9\ntf.matrix_diag_part(input, k = (1, 3), padding_value = 9)\n ==\u003e [[[9, 9, 4], # Output shape: (2, 3, 3)\n [9, 3, 8],\n [2, 7, 6]],\n [[9, 9, 2],\n [9, 3, 4],\n [4, 3, 8]]]\n```\n\n\u003cbr /\u003e\n\n\n````gdscript\n \n Arguments:\n \n- scope: A /versions/r2.2/api_docs/cc/class/tensorflow/scope#classtensorflow_1_1_scope object\n\n \n- input: Rank r tensor where r \u003e= 2.\n\n \n- k: Diagonal offset(s). Positive value means superdiagonal, 0 refers to the main diagonal, and negative value means subdiagonals. k can be a single integer (for a single diagonal) or a pair of integers specifying the low and high ends of a matrix band. k[0] must not be larger than k[1].\n\n \n- padding_value: The value to fill the area outside the specified diagonal band with. Default is 0.\n\n \n\n Optional attributes (see /versions/r2.2/api_docs/cc/struct/tensorflow/ops/matrix-diag-part-v3/attrs#structtensorflow_1_1ops_1_1_matrix_diag_part_v3_1_1_attrs):\n \n- align: Some diagonals are shorter than max_diag_len and need to be padded. align is a string specifying how superdiagonals and subdiagonals should be aligned, respectively. There are four possible alignments: \"RIGHT_LEFT\" (default), \"LEFT_RIGHT\", \"LEFT_LEFT\", and \"RIGHT_RIGHT\". \"RIGHT_LEFT\" aligns superdiagonals to the right (left-pads the row) and subdiagonals to the left (right-pads the row). It is the packing format LAPACK uses. cuSPARSE uses \"LEFT_RIGHT\", which is the opposite alignment.\n\n \n\n Returns:\n \n- /versions/r2.2/api_docs/cc/class/tensorflow/output#classtensorflow_1_1_output: The extracted diagonal(s). \n\n \n\n \n\n\n \n### Constructors and Destructors\n\n\n \n\n\n\n #classtensorflow_1_1ops_1_1_matrix_diag_part_v3_1abda51edecba9f012bd9118b2b4e4eb39(const ::/versions/r2.2/api_docs/cc/class/tensorflow/scope#classtensorflow_1_1_scope & scope, ::/versions/r2.2/api_docs/cc/class/tensorflow/input#classtensorflow_1_1_input input, ::/versions/r2.2/api_docs/cc/class/tensorflow/input#classtensorflow_1_1_input k, ::/versions/r2.2/api_docs/cc/class/tensorflow/input#classtensorflow_1_1_input padding_value)\n \n\n \n\n\n\n #classtensorflow_1_1ops_1_1_matrix_diag_part_v3_1ab2a7181a88ac68c2c1f8aa8e54d94f36(const ::/versions/r2.2/api_docs/cc/class/tensorflow/scope#classtensorflow_1_1_scope & scope, ::/versions/r2.2/api_docs/cc/class/tensorflow/input#classtensorflow_1_1_input input, ::/versions/r2.2/api_docs/cc/class/tensorflow/input#classtensorflow_1_1_input k, ::/versions/r2.2/api_docs/cc/class/tensorflow/input#classtensorflow_1_1_input padding_value, const /versions/r2.2/api_docs/cc/struct/tensorflow/ops/matrix-diag-part-v3/attrs#structtensorflow_1_1ops_1_1_matrix_diag_part_v3_1_1_attrs & attrs)\n \n\n \n\n\n \n\n\n \n### Public attributes\n\n\n \n\n\n\n #classtensorflow_1_1ops_1_1_matrix_diag_part_v3_1ab5b1ebb490b4c3ac451095ad9c2860ce\n \n\n \n\n ::/versions/r2.2/api_docs/cc/class/tensorflow/output#classtensorflow_1_1_output\n \n\n \n\n\n\n #classtensorflow_1_1ops_1_1_matrix_diag_part_v3_1aab8e9d1b13b2fafd7954d2acc89077f3\n \n\n \n\n /versions/r2.2/api_docs/cc/class/tensorflow/operation#classtensorflow_1_1_operation\n \n\n \n\n\n \n\n\n \n### Public functions\n\n\n \n\n\n\n #classtensorflow_1_1ops_1_1_matrix_diag_part_v3_1a42ebd82d85100f3cae0b90acce7c7d41() const \n \n\n \n\n ::tensorflow::Node *\n \n\n \n\n\n\n #classtensorflow_1_1ops_1_1_matrix_diag_part_v3_1a077796bdba19bb0c51a49a758b47b2f7() const \n \n\n \n\n `\n` \n`\n` \n\n\n\n #classtensorflow_1_1ops_1_1_matrix_diag_part_v3_1aad6d6537777dd1424e046801937d308c() const \n \n\n \n\n `\n` \n`\n` \n\n\n \n\n\n \n### Public static functions\n\n\n \n\n\n\n #classtensorflow_1_1ops_1_1_matrix_diag_part_v3_1a2bd0085f20db6aaa612f12494bfd9c6e(StringPiece x)\n \n\n \n\n /versions/r2.2/api_docs/cc/struct/tensorflow/ops/matrix-diag-part-v3/attrs#structtensorflow_1_1ops_1_1_matrix_diag_part_v3_1_1_attrs\n \n\n \n\n\n \n\n\n \n### Structs\n\n\n \n\n\n\n /versions/r2.2/api_docs/cc/struct/tensorflow/ops/matrix-diag-part-v3/attrs\n \n\n \nOptional attribute setters for /versions/r2.2/api_docs/cc/class/tensorflow/ops/matrix-diag-part-v3#classtensorflow_1_1ops_1_1_matrix_diag_part_v3. \n\n \n\n\n Public attributes\n \n \n### diagonal\n\n\n \n```\n::tensorflow::Output diagonal\n```\n\n \n\n \n \n \n### operation\n\n\n \n\n\n```text\nOperation operation\n```\n\n \n\n \n Public functions\n \n \n### MatrixDiagPartV3\n\n\n \n\n\n```gdscript\n MatrixDiagPartV3(\n const ::tensorflow::Scope & scope,\n ::tensorflow::Input input,\n ::tensorflow::Input k,\n ::tensorflow::Input padding_value\n)\n```\n\n \n\n \n \n \n### MatrixDiagPartV3\n\n\n \n\n\n```gdscript\n MatrixDiagPartV3(\n const ::tensorflow::Scope & scope,\n ::tensorflow::Input input,\n ::tensorflow::Input k,\n ::tensorflow::Input padding_value,\n const MatrixDiagPartV3::Attrs & attrs\n)\n```\n\n \n\n \n \n \n### node\n\n\n \n\n\n```gdscript\n::tensorflow::Node * node() const \n```\n\n \n\n \n \n \n### operator::tensorflow::Input\n\n\n \n\n\n```gdscript\n operator::tensorflow::Input() const \n```\n\n \n\n \n \n \n### operator::tensorflow::Output\n\n\n \n\n\n```gdscript\n operator::tensorflow::Output() const \n```\n\n \n\n \n Public static functions\n \n \n### Align\n\n\n \n\n\n```text\nAttrs Align(\n StringPiece x\n)\n```\n\n \n\n \n\n \n\n \n````"]]