จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
เทนเซอร์โฟลว์:: ปฏิบัติการ:: MatrixDiagV2
#include <array_ops.h>
ส่งกลับเทนเซอร์แนวทแยงแบบแบทช์พร้อมค่าแนวทแยงแบบแบทช์ที่กำหนด
สรุป
ส่งกลับเทนเซอร์ที่มีเนื้อหาอยู่ใน diagonal
เป็น k[0]
-th ถึง k[1]
-th diagonals ของเมทริกซ์ โดยที่อย่างอื่นมีช่อง padding
num_rows
และ num_cols
ระบุขนาดของเมทริกซ์ด้านในสุดของเอาต์พุต หากไม่ได้ระบุทั้งคู่ op จะถือว่าเมทริกซ์ด้านในสุดเป็นสี่เหลี่ยมจัตุรัสและอนุมานขนาดจาก k
และมิติด้านในสุดของ diagonal
หากมีการระบุเพียงค่าเดียว op จะถือว่าค่าที่ไม่ได้ระบุมีค่าน้อยที่สุดที่เป็นไปได้ตามเกณฑ์อื่นๆ
ให้ diagonal
มีมิติ r
[I, J, ..., L, M, N]
. เทนเซอร์เอาท์พุตมีอันดับ r+1
ที่มีรูปร่าง [I, J, ..., L, M, num_rows, num_cols]
เมื่อให้เพียงหนึ่งเส้นทแยงมุม ( k
เป็นจำนวนเต็มหรือ k[0] == k[1]
) . มิฉะนั้นจะมีอันดับ r
ที่มีรูปร่าง [I, J, ..., L, num_rows, num_cols]
มิติในสุดที่สองของ diagonal
มีความหมายสองเท่า เมื่อ k
เป็นสเกลาร์หรือ k[0] == k[1]
, M
จะเป็นส่วนหนึ่งของขนาดแบตช์ [I, J, ..., M] และเอาท์พุตเทนเซอร์คือ:
output[i, j, ..., l, m, n]
= diagonal[i, j, ..., l, n-max(d_upper, 0)] ; if n - m == d_upper
output[i, j, ..., l, m, n] ; otherwise
มิฉะนั้น M
จะถือเป็นจำนวนเส้นทแยงมุมสำหรับเมทริกซ์ในชุดเดียวกัน ( M = k[1]-k[0]+1
) และเทนเซอร์เอาท์พุตคือ:
output[i, j, ..., l, m, n]
= diagonal[i, j, ..., l, k[1]-d, n-max(d, 0)] ; if d_lower <= d <= d_upper
input[i, j, ..., l, m, n] ; otherwise
โดยที่
d = n - m
ตัวอย่างเช่น:
# The main diagonal.
diagonal = np.array([[1, 2, 3, 4], # Input shape: (2, 4)
[5, 6, 7, 8]])
tf.matrix_diag(diagonal) ==> [[[1, 0, 0, 0], # Output shape: (2, 4, 4)
[0, 2, 0, 0],
[0, 0, 3, 0],
[0, 0, 0, 4]],
[[5, 0, 0, 0],
[0, 6, 0, 0],
[0, 0, 7, 0],
[0, 0, 0, 8]]]
# A superdiagonal (per batch).
diagonal = np.array([[1, 2, 3], # Input shape: (2, 3)
[4, 5, 6]])
tf.matrix_diag(diagonal, k = 1)
==> [[[0, 1, 0, 0], # Output shape: (2, 4, 4)
[0, 0, 2, 0],
[0, 0, 0, 3],
[0, 0, 0, 0]],
[[0, 4, 0, 0],
[0, 0, 5, 0],
[0, 0, 0, 6],
[0, 0, 0, 0]]]
# A band of diagonals.
diagonals = np.array([[[1, 2, 3], # Input shape: (2, 2, 3)
[4, 5, 0]],
[[6, 7, 9],
[9, 1, 0]]])
tf.matrix_diag(diagonals, k = (-1, 0))
==> [[[1, 0, 0], # Output shape: (2, 3, 3)
[4, 2, 0],
[0, 5, 3]],
[[6, 0, 0],
[9, 7, 0],
[0, 1, 9]]]
# Rectangular matrix.
diagonal = np.array([1, 2]) # Input shape: (2)
tf.matrix_diag(diagonal, k = -1, num_rows = 3, num_cols = 4)
==> [[0, 0, 0, 0], # Output shape: (3, 4)
[1, 0, 0, 0],
[0, 2, 0, 0]]
# Rectangular matrix with inferred num_cols and padding = 9.
tf.matrix_diag(diagonal, k = -1, num_rows = 3, padding = 9)
==> [[9, 9], # Output shape: (3, 2)
[1, 9],
[9, 2]]
ข้อโต้แย้ง:
- ขอบเขต: วัตถุ ขอบเขต
- เส้นทแยงมุม: อันดับ
r
โดยที่ r >= 1
- k: ออฟเซ็ตแนวทแยง ค่าบวกหมายถึงเส้นทแยงมุมเหนือ, 0 หมายถึงเส้นทแยงมุมหลัก และค่าลบหมายถึงเส้นทแยงมุมย่อย
k
อาจเป็นจำนวนเต็มเดี่ยว (สำหรับเส้นทแยงมุมเดียว) หรือจำนวนเต็มคู่ที่ระบุจุดต่ำสุดและสูงของแถบเมทริกซ์ k[0]
จะต้องไม่ใหญ่กว่า k[1]
- num_rows: จำนวนแถวของเมทริกซ์เอาต์พุต หากไม่ได้ระบุไว้ op จะถือว่าเมทริกซ์เอาต์พุตเป็นเมทริกซ์จัตุรัสและอนุมานขนาดเมทริกซ์จาก k และมิติด้านในสุดของ
diagonal
- num_cols: จำนวนคอลัมน์ของเมทริกซ์เอาต์พุต หากไม่ได้ระบุไว้ op จะถือว่าเมทริกซ์เอาต์พุตเป็นเมทริกซ์จัตุรัสและอนุมานขนาดเมทริกซ์จาก k และมิติด้านในสุดของ
diagonal
- padding_value: จำนวนที่จะเติมพื้นที่นอกแถบแนวทแยงที่ระบุด้วย ค่าเริ่มต้นคือ 0
ผลตอบแทน:
-
Output
: มีอันดับ r+1
เมื่อ k
เป็นจำนวนเต็มหรือ k[0] == k[1]
อันดับ r
มิฉะนั้น
คุณลักษณะสาธารณะ
งานสาธารณะ
โหนด
::tensorflow::Node * node() const
operator::tensorflow::Input() const
ตัวดำเนินการ::tensorflow::เอาต์พุต
operator::tensorflow::Output() const
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-07-26 UTC
[null,null,["อัปเดตล่าสุด 2025-07-26 UTC"],[],[],null,["# tensorflow::ops::MatrixDiagV2 Class Reference\n\ntensorflow::ops::MatrixDiagV2\n=============================\n\n`#include \u003carray_ops.h\u003e`\n\nReturns a batched diagonal tensor with given batched diagonal values.\n\nSummary\n-------\n\nReturns a tensor with the contents in `diagonal` as `k[0]`-th to `k[1]`-th diagonals of a matrix, with everything else padded with `padding`. `num_rows` and `num_cols` specify the dimension of the innermost matrix of the output. If both are not specified, the op assumes the innermost matrix is square and infers its size from `k` and the innermost dimension of `diagonal`. If only one of them is specified, the op assumes the unspecified value is the smallest possible based on other criteria.\n\nLet `diagonal` have `r` dimensions `[I, J, ..., L, M, N]`. The output tensor has rank `r+1` with shape `[I, J, ..., L, M, num_rows, num_cols]` when only one diagonal is given (`k` is an integer or `k[0] == k[1]`). Otherwise, it has rank `r` with shape `[I, J, ..., L, num_rows, num_cols]`.\n\nThe second innermost dimension of `diagonal` has double meaning. When `k` is scalar or `k[0] == k[1]`, `M` is part of the batch size \\[I, J, ..., M\\], and the output tensor is:\n\n\n```scdoc\noutput[i, j, ..., l, m, n]\n = diagonal[i, j, ..., l, n-max(d_upper, 0)] ; if n - m == d_upper\n output[i, j, ..., l, m, n] ; otherwise\n```\n\n\u003cbr /\u003e\n\nOtherwise, `M` is treated as the number of diagonals for the matrix in the same batch (`M = k[1]-k[0]+1`), and the output tensor is:\n\n\u003cbr /\u003e\n\n```scdoc\noutput[i, j, ..., l, m, n]\n = diagonal[i, j, ..., l, k[1]-d, n-max(d, 0)] ; if d_lower \u003c= d \u003c= d_upper\n input[i, j, ..., l, m, n] ; otherwise\n```\nwhere `d = n - m`\n\n\u003cbr /\u003e\n\nFor example:\n\n\n```scdoc\n# The main diagonal.\ndiagonal = np.array([[1, 2, 3, 4], # Input shape: (2, 4)\n [5, 6, 7, 8]])\ntf.matrix_diag(diagonal) ==\u003e [[[1, 0, 0, 0], # Output shape: (2, 4, 4)\n [0, 2, 0, 0],\n [0, 0, 3, 0],\n [0, 0, 0, 4]],\n [[5, 0, 0, 0],\n [0, 6, 0, 0],\n [0, 0, 7, 0],\n [0, 0, 0, 8]]]\n```\n\n\u003cbr /\u003e\n\n\n```scdoc\n# A superdiagonal (per batch).\ndiagonal = np.array([[1, 2, 3], # Input shape: (2, 3)\n [4, 5, 6]])\ntf.matrix_diag(diagonal, k = 1)\n ==\u003e [[[0, 1, 0, 0], # Output shape: (2, 4, 4)\n [0, 0, 2, 0],\n [0, 0, 0, 3],\n [0, 0, 0, 0]],\n [[0, 4, 0, 0],\n [0, 0, 5, 0],\n [0, 0, 0, 6],\n [0, 0, 0, 0]]]\n```\n\n\u003cbr /\u003e\n\n\n```scdoc\n# A band of diagonals.\ndiagonals = np.array([[[1, 2, 3], # Input shape: (2, 2, 3)\n [4, 5, 0]],\n [[6, 7, 9],\n [9, 1, 0]]])\ntf.matrix_diag(diagonals, k = (-1, 0))\n ==\u003e [[[1, 0, 0], # Output shape: (2, 3, 3)\n [4, 2, 0],\n [0, 5, 3]],\n [[6, 0, 0],\n [9, 7, 0],\n [0, 1, 9]]]\n```\n\n\u003cbr /\u003e\n\n\n```scdoc\n# Rectangular matrix.\ndiagonal = np.array([1, 2]) # Input shape: (2)\ntf.matrix_diag(diagonal, k = -1, num_rows = 3, num_cols = 4)\n ==\u003e [[0, 0, 0, 0], # Output shape: (3, 4)\n [1, 0, 0, 0],\n [0, 2, 0, 0]]\n```\n\n\u003cbr /\u003e\n\n\n```scdoc\n# Rectangular matrix with inferred num_cols and padding = 9.\ntf.matrix_diag(diagonal, k = -1, num_rows = 3, padding = 9)\n ==\u003e [[9, 9], # Output shape: (3, 2)\n [1, 9],\n [9, 2]]\n```\n\n\u003cbr /\u003e\n\nArguments:\n\n- scope: A [Scope](/versions/r2.0/api_docs/cc/class/tensorflow/scope#classtensorflow_1_1_scope) object\n- diagonal: Rank `r`, where `r \u003e= 1`\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- num_rows: The number of rows of the output matrix. If it is not provided, the op assumes the output matrix is a square matrix and infers the matrix size from k and the innermost dimension of `diagonal`.\n- num_cols: The number of columns of the output matrix. If it is not provided, the op assumes the output matrix is a square matrix and infers the matrix size from k and the innermost dimension of `diagonal`.\n- padding_value: The number to fill the area outside the specified diagonal band with. Default is 0.\n\n\u003cbr /\u003e\n\nReturns:\n\n- [Output](/versions/r2.0/api_docs/cc/class/tensorflow/output#classtensorflow_1_1_output): Has rank `r+1` when `k` is an integer or `k[0] == k[1]`, rank `r` otherwise.\n\n\u003cbr /\u003e\n\n| ### Constructors and Destructors ||\n|---|---|\n| [MatrixDiagV2](#classtensorflow_1_1ops_1_1_matrix_diag_v2_1a0f4757e436efeaed1ba2bd9690367b7f)`(const ::`[tensorflow::Scope](/versions/r2.0/api_docs/cc/class/tensorflow/scope#classtensorflow_1_1_scope)` & scope, ::`[tensorflow::Input](/versions/r2.0/api_docs/cc/class/tensorflow/input#classtensorflow_1_1_input)` diagonal, ::`[tensorflow::Input](/versions/r2.0/api_docs/cc/class/tensorflow/input#classtensorflow_1_1_input)` k, ::`[tensorflow::Input](/versions/r2.0/api_docs/cc/class/tensorflow/input#classtensorflow_1_1_input)` num_rows, ::`[tensorflow::Input](/versions/r2.0/api_docs/cc/class/tensorflow/input#classtensorflow_1_1_input)` num_cols, ::`[tensorflow::Input](/versions/r2.0/api_docs/cc/class/tensorflow/input#classtensorflow_1_1_input)` padding_value)` ||\n\n| ### Public attributes ||\n|--------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------|\n| [operation](#classtensorflow_1_1ops_1_1_matrix_diag_v2_1a09bb44acf7362d90e9b70dfaa3ebd8fd) | [Operation](/versions/r2.0/api_docs/cc/class/tensorflow/operation#classtensorflow_1_1_operation) |\n| [output](#classtensorflow_1_1ops_1_1_matrix_diag_v2_1a180f0e2069ba614f9a8bf4593d6b322a) | `::`[tensorflow::Output](/versions/r2.0/api_docs/cc/class/tensorflow/output#classtensorflow_1_1_output) |\n\n| ### Public functions ||\n|--------------------------------------------------------------------------------------------------------------------------|------------------------|\n| [node](#classtensorflow_1_1ops_1_1_matrix_diag_v2_1a5faf264fc6c643dfc49d1d5b00828973)`() const ` | `::tensorflow::Node *` |\n| [operator::tensorflow::Input](#classtensorflow_1_1ops_1_1_matrix_diag_v2_1a8301ec1ffa503e41034e06b9fc8dfd93)`() const ` | ` ` ` ` |\n| [operator::tensorflow::Output](#classtensorflow_1_1ops_1_1_matrix_diag_v2_1a96f20bc6c061cadeeb30e3986311fc2c)`() const ` | ` ` ` ` |\n\nPublic attributes\n-----------------\n\n### operation\n\n```text\nOperation operation\n``` \n\n### output\n\n```text\n::tensorflow::Output output\n``` \n\nPublic functions\n----------------\n\n### MatrixDiagV2\n\n```gdscript\n MatrixDiagV2(\n const ::tensorflow::Scope & scope,\n ::tensorflow::Input diagonal,\n ::tensorflow::Input k,\n ::tensorflow::Input num_rows,\n ::tensorflow::Input num_cols,\n ::tensorflow::Input padding_value\n)\n``` \n\n### node\n\n```gdscript\n::tensorflow::Node * node() const \n``` \n\n### operator::tensorflow::Input\n\n```gdscript\n operator::tensorflow::Input() const \n``` \n\n### operator::tensorflow::Output\n\n```gdscript\n operator::tensorflow::Output() const \n```"]]