コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
テンソルフロー::作戦:: MatrixSetDiagV2
#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)
です。
例えば:
# 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(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(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([[[1, 2, 3], # Diagonal shape: (2, 2, 3)
[4, 5, 0]],
[[6, 1, 2],
[3, 4, 0]]])
tf.matrix_set_diag(diagonals, k = (-1, 0))
==> [[[1, 7, 7, 7], # Output shape: (2, 3, 4)
[4, 2, 7, 7],
[0, 5, 3, 7]],
[[6, 7, 7, 7],
[3, 1, 7, 7],
[7, 4, 2, 7]]]
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]
.
Returns:
Output
: Rank r+1
, with output.shape = input.shape
.
Public attributes
公共機能
ノード
::tensorflow::Node * node() const
operator::tensorflow::Input() const
演算子::tensorflow::出力
operator::tensorflow::Output() const
特に記載のない限り、このページのコンテンツはクリエイティブ・コモンズの表示 4.0 ライセンスにより使用許諾されます。コードサンプルは Apache 2.0 ライセンスにより使用許諾されます。詳しくは、Google Developers サイトのポリシーをご覧ください。Java は Oracle および関連会社の登録商標です。
最終更新日 2025-07-27 UTC。
[null,null,["最終更新日 2025-07-27 UTC。"],[],[],null,["# tensorflow::ops::MatrixSetDiagV2 Class Reference\n\ntensorflow::ops::MatrixSetDiagV2\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)`.\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(diagonal) ==\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(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([[[1, 2, 3], # Diagonal shape: (2, 2, 3)\n [4, 5, 0]],\n [[6, 1, 2],\n [3, 4, 0]]])\ntf.matrix_set_diag(diagonals, k = (-1, 0))\n ==\u003e [[[1, 7, 7, 7], # Output shape: (2, 3, 4)\n [4, 2, 7, 7],\n [0, 5, 3, 7]],\n [[6, 7, 7, 7],\n [3, 1, 7, 7],\n [7, 4, 2, 7]]]\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 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_v2_1a438f858712bda6df180ee19d8f278bf4(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\n\n \n### Public attributes\n\n\n \n\n\n\n #classtensorflow_1_1ops_1_1_matrix_set_diag_v2_1a433c91a80772823c3acd4729a873900f\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_v2_1a390fc69019f7170f80f7c4c3acb12cee\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_v2_1ab0f95dc9ddcb2221701f55c8caddcdb1() const \n \n\n \n\n ::tensorflow::Node *\n \n\n \n\n\n\n #classtensorflow_1_1ops_1_1_matrix_set_diag_v2_1a333c742af8203776572da9009d8c0930() const \n \n\n \n\n `\n` \n`\n` \n\n\n\n #classtensorflow_1_1ops_1_1_matrix_set_diag_v2_1a0574bd8260d99f8d93fa3a0cb880f0fa() const \n \n\n \n\n `\n` \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### MatrixSetDiagV2\n\n\n \n\n\n```gdscript\n MatrixSetDiagV2(\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### 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\n \n\n \n````"]]