컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
텐서플로우:: 작전:: MatrixSetDiagV3
#include <array_ops.h>
새로운 배치 대각선 값을 갖는 배치 행렬 텐서를 반환합니다.
요약
input
및 diagonal
주어지면 이 연산은 가장 안쪽 행렬의 지정된 대각선을 제외하고 input
과 동일한 모양 및 값을 가진 텐서를 반환합니다. 이는 diagonal
값으로 덮어쓰여집니다.
input
r+1
차원 [I, J, ..., L, M, N]
이 있습니다. k
가 스칼라이거나 k[0] == k[1]
인 경우 diagonal
r
차원 [I, J, ..., L, max_diag_len]
을 갖습니다. 그렇지 않으면 r+1
차원 [I, J, ..., L, num_diags, max_diag_len]
을 갖습니다. num_diags
는 대각선 수입니다. num_diags = k[1] - k[0] + 1
. max_diag_len
[k[0], k[1]]
범위에서 가장 긴 대각선입니다 max_diag_len = min(M + min(k[1], 0), N + min(-k[0], 0))
출력은 [I, J, ..., L, M, N]
차원을 갖는 k+1
순위의 텐서입니다. k
가 스칼라이거나 k[0] == k[1]
인 경우:
output[i, j, ..., l, m, n]
= diagonal[i, j, ..., l, n-max(k[1], 0)] ; if n - m == k[1]
input[i, j, ..., l, m, n] ; otherwise
그렇지 않으면,
output[i, j, ..., l, m, n]
= diagonal[i, j, ..., l, diag_index, index_in_diag] ; if k[0] <= d <= k[1]
input[i, j, ..., l, m, n] ; otherwise
여기서
d = n - m
,
diag_index = k[1] - d
및
index_in_diag = n - max(d, 0) + offset
.
대각선 정렬이 오른쪽인 경우를 제외하고 offset
은 0입니다.
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
여기서
diag_len(d) = min(cols - max(d, 0), rows + min(d, 0))
.
예를 들어:
# The main diagonal.
input = np.array([[[7, 7, 7, 7], # Input shape: (2, 3, 4)
[7, 7, 7, 7],
[7, 7, 7, 7]],
[[7, 7, 7, 7],
[7, 7, 7, 7],
[7, 7, 7, 7]]])
diagonal = np.array([[1, 2, 3], # Diagonal shape: (2, 3)
[4, 5, 6]])
tf.matrix_set_diag(input, diagonal)
==> [[[1, 7, 7, 7], # Output shape: (2, 3, 4)
[7, 2, 7, 7],
[7, 7, 3, 7]],
[[4, 7, 7, 7],
[7, 5, 7, 7],
[7, 7, 6, 7]]]
# A superdiagonal (per batch).
tf.matrix_set_diag(input, diagonal, k = 1)
==> [[[7, 1, 7, 7], # Output shape: (2, 3, 4)
[7, 7, 2, 7],
[7, 7, 7, 3]],
[[7, 4, 7, 7],
[7, 7, 5, 7],
[7, 7, 7, 6]]]
# A band of diagonals.
diagonals = np.array([[[0, 9, 1], # Diagonal shape: (2, 4, 3)
[6, 5, 8],
[1, 2, 3],
[4, 5, 0]],
[[0, 1, 2],
[5, 6, 4],
[6, 1, 2],
[3, 4, 0]]])
tf.matrix_set_diag(input, diagonals, k = (-1, 2))
==> [[[1, 6, 9, 7], # Output shape: (2, 3, 4)
[4, 2, 5, 1],
[7, 5, 3, 8]],
[[6, 5, 1, 7],
[3, 1, 6, 2],
[7, 4, 2, 4]]]
# LEFT_RIGHT alignment.
diagonals = np.array([[[9, 1, 0], # Diagonal shape: (2, 4, 3)
[6, 5, 8],
[1, 2, 3],
[0, 4, 5]],
[[1, 2, 0],
[5, 6, 4],
[6, 1, 2],
[0, 3, 4]]])
tf.matrix_set_diag(input, diagonals, k = (-1, 2), align="LEFT_RIGHT")
==> [[[1, 6, 9, 7], # Output shape: (2, 3, 4)
[4, 2, 5, 1],
[7, 5, 3, 8]],
[[6, 5, 1, 7],
[3, 1, 6, 2],
[7, 4, 2, 4]]]
Arguments:
- scope: A Scope object
- input: Rank
r+1
, where r >= 1
.
- diagonal: Rank
r
when k
is an integer or k[0] == k[1]
. Otherwise, it has rank r+1
. k >= 1
.
- 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]
.
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
: Rank r+1
, with output.shape = input.shape
.
Public static functions
|
Align(StringPiece x)
|
|
Public attributes
공공 기능
마디
::tensorflow::Node * node() const
operator::tensorflow::Input() const
연산자::텐서플로우::출력
operator::tensorflow::Output() const
공개 정적 함수
맞추다
Attrs Align(
StringPiece x
)
달리 명시되지 않는 한 이 페이지의 콘텐츠에는 Creative Commons Attribution 4.0 라이선스에 따라 라이선스가 부여되며, 코드 샘플에는 Apache 2.0 라이선스에 따라 라이선스가 부여됩니다. 자세한 내용은 Google Developers 사이트 정책을 참조하세요. 자바는 Oracle 및/또는 Oracle 계열사의 등록 상표입니다.
최종 업데이트: 2025-07-27(UTC)
[null,null,["최종 업데이트: 2025-07-27(UTC)"],[],[],null,["# tensorflow::ops::MatrixSetDiagV3 Class Reference\n\ntensorflow::ops::MatrixSetDiagV3\n================================\n\n`#include \u003carray_ops.h\u003e`\n\nReturns a batched matrix tensor with new batched diagonal values.\n\nSummary\n-------\n\nGiven `input` and `diagonal`, this operation returns a tensor with the same shape and values as `input`, except for the specified diagonals of the innermost matrices. These will be overwritten by the values in `diagonal`.\n\n`input` has `r+1` dimensions `[I, J, ..., L, M, N]`. When `k` is scalar or `k[0] == k[1]`, `diagonal` has `r` dimensions `[I, J, ..., L, max_diag_len]`. Otherwise, it has `r+1` dimensions `[I, J, ..., L, num_diags, max_diag_len]`. `num_diags` is the number of diagonals, `num_diags = k[1] - k[0] + 1`. `max_diag_len` is the longest diagonal in the range `[k[0], k[1]]`, `max_diag_len = min(M + min(k[1], 0), N + min(-k[0], 0))`\n\nThe output is a tensor of rank `k+1` with dimensions `[I, J, ..., L, M, N]`. If `k` is scalar or `k[0] == k[1]`:\n\n\n```text\noutput[i, j, ..., l, m, n]\n = diagonal[i, j, ..., l, n-max(k[1], 0)] ; if n - m == k[1]\n input[i, j, ..., l, m, n] ; otherwise\n```\n\n\u003cbr /\u003e\n\nOtherwise,\n\n\u003cbr /\u003e\n\n```scdoc\noutput[i, j, ..., l, m, n]\n = diagonal[i, j, ..., l, diag_index, index_in_diag] ; if k[0] \u003c= d \u003c= k[1]\n input[i, j, ..., l, m, n] ; otherwise\n```\nwhere `d = n - m`, `diag_index = k[1] - d`, and `index_in_diag = n - 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\nFor example:\n\n\n```scdoc\n# The main diagonal.\ninput = np.array([[[7, 7, 7, 7], # Input shape: (2, 3, 4)\n [7, 7, 7, 7],\n [7, 7, 7, 7]],\n [[7, 7, 7, 7],\n [7, 7, 7, 7],\n [7, 7, 7, 7]]])\ndiagonal = np.array([[1, 2, 3], # Diagonal shape: (2, 3)\n [4, 5, 6]])\ntf.matrix_set_diag(input, diagonal)\n ==\u003e [[[1, 7, 7, 7], # Output shape: (2, 3, 4)\n [7, 2, 7, 7],\n [7, 7, 3, 7]],\n [[4, 7, 7, 7],\n [7, 5, 7, 7],\n [7, 7, 6, 7]]]\n```\n\n\u003cbr /\u003e\n\n\n```scdoc\n# A superdiagonal (per batch).\ntf.matrix_set_diag(input, diagonal, k = 1)\n ==\u003e [[[7, 1, 7, 7], # Output shape: (2, 3, 4)\n [7, 7, 2, 7],\n [7, 7, 7, 3]],\n [[7, 4, 7, 7],\n [7, 7, 5, 7],\n [7, 7, 7, 6]]]\n```\n\n\u003cbr /\u003e\n\n\n```scdoc\n# A band of diagonals.\ndiagonals = np.array([[[0, 9, 1], # Diagonal shape: (2, 4, 3)\n [6, 5, 8],\n [1, 2, 3],\n [4, 5, 0]],\n [[0, 1, 2],\n [5, 6, 4],\n [6, 1, 2],\n [3, 4, 0]]])\ntf.matrix_set_diag(input, diagonals, k = (-1, 2))\n ==\u003e [[[1, 6, 9, 7], # Output shape: (2, 3, 4)\n [4, 2, 5, 1],\n [7, 5, 3, 8]],\n [[6, 5, 1, 7],\n [3, 1, 6, 2],\n [7, 4, 2, 4]]]\n```\n\n\u003cbr /\u003e\n\n\n```scdoc\n# LEFT_RIGHT alignment.\ndiagonals = np.array([[[9, 1, 0], # Diagonal shape: (2, 4, 3)\n [6, 5, 8],\n [1, 2, 3],\n [0, 4, 5]],\n [[1, 2, 0],\n [5, 6, 4],\n [6, 1, 2],\n [0, 3, 4]]])\ntf.matrix_set_diag(input, diagonals, k = (-1, 2), align=\"LEFT_RIGHT\")\n ==\u003e [[[1, 6, 9, 7], # Output shape: (2, 3, 4)\n [4, 2, 5, 1],\n [7, 5, 3, 8]],\n [[6, 5, 1, 7],\n [3, 1, 6, 2],\n [7, 4, 2, 4]]]\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+1, where r \u003e= 1.\n\n \n- diagonal: Rank r when k is an integer or k[0] == k[1]. Otherwise, it has rank r+1. k \u003e= 1.\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\n Optional attributes (see /versions/r2.2/api_docs/cc/struct/tensorflow/ops/matrix-set-diag-v3/attrs#structtensorflow_1_1ops_1_1_matrix_set_diag_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: Rank r+1, with output.shape = input.shape. \n\n \n\n \n\n\n \n### Constructors and Destructors\n\n\n \n\n\n\n #classtensorflow_1_1ops_1_1_matrix_set_diag_v3_1aa1c50423313605b235615b20b525285d(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 diagonal, ::/versions/r2.2/api_docs/cc/class/tensorflow/input#classtensorflow_1_1_input k)\n \n\n \n\n\n\n #classtensorflow_1_1ops_1_1_matrix_set_diag_v3_1a581008278c2f4caccfe290b868cc9790(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 diagonal, ::/versions/r2.2/api_docs/cc/class/tensorflow/input#classtensorflow_1_1_input k, const /versions/r2.2/api_docs/cc/struct/tensorflow/ops/matrix-set-diag-v3/attrs#structtensorflow_1_1ops_1_1_matrix_set_diag_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_set_diag_v3_1aa97bc3e979e617469d1ef1df3b816663\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 #classtensorflow_1_1ops_1_1_matrix_set_diag_v3_1a07f228688563f554887686af516dd9a1\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\n\n \n### Public functions\n\n\n \n\n\n\n #classtensorflow_1_1ops_1_1_matrix_set_diag_v3_1a15eca00505d35ebcd159a9fb0fab1640() const \n \n\n \n\n ::tensorflow::Node *\n \n\n \n\n\n\n #classtensorflow_1_1ops_1_1_matrix_set_diag_v3_1af545db03e9535f6c8be459ac4b684047() const \n \n\n \n\n `\n` \n`\n` \n\n\n\n #classtensorflow_1_1ops_1_1_matrix_set_diag_v3_1a9005a31328cf4653bd9fda4ff88b6bbf() 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_set_diag_v3_1a60c1784ebf8f798d1b35e1143c07b467(StringPiece x)\n \n\n \n\n /versions/r2.2/api_docs/cc/struct/tensorflow/ops/matrix-set-diag-v3/attrs#structtensorflow_1_1ops_1_1_matrix_set_diag_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-set-diag-v3/attrs\n \n\n \nOptional attribute setters for /versions/r2.2/api_docs/cc/class/tensorflow/ops/matrix-set-diag-v3#classtensorflow_1_1ops_1_1_matrix_set_diag_v3. \n\n \n\n\n Public attributes\n \n \n### operation\n\n\n \n```\nOperation operation\n```\n\n \n\n \n \n \n### output\n\n\n \n\n\n```text\n::tensorflow::Output output\n```\n\n \n\n \n Public functions\n \n \n### MatrixSetDiagV3\n\n\n \n\n\n```gdscript\n MatrixSetDiagV3(\n const ::tensorflow::Scope & scope,\n ::tensorflow::Input input,\n ::tensorflow::Input diagonal,\n ::tensorflow::Input k\n)\n```\n\n \n\n \n \n \n### MatrixSetDiagV3\n\n\n \n\n\n```gdscript\n MatrixSetDiagV3(\n const ::tensorflow::Scope & scope,\n ::tensorflow::Input input,\n ::tensorflow::Input diagonal,\n ::tensorflow::Input k,\n const MatrixSetDiagV3::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````"]]