จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
เทนเซอร์โฟลว์:: ปฏิบัติการ:: วินิจฉัย
#include <array_ops.h>
ส่งกลับเทนเซอร์แนวทแยงด้วยค่าแนวทแยงที่กำหนด
สรุป
เมื่อกำหนด diagonal
การดำเนินการนี้จะส่งคืนเทนเซอร์ที่มี diagonal
และทุกอย่างเสริมด้วยศูนย์ เส้นทแยงมุมคำนวณดังนี้:
สมมติว่า diagonal
มีขนาด [D1,..., Dk] ดังนั้นเอาต์พุตจะเป็นเทนเซอร์อันดับ 2k โดยมีขนาด [D1,..., Dk, D1,..., Dk] โดยที่:
output[i1,..., ik, i1,..., ik] = diagonal[i1, ..., ik]
และ 0 ทุกที่
ตัวอย่างเช่น:
# 'diagonal' is [1, 2, 3, 4]
tf.diag(diagonal) ==> [[1, 0, 0, 0]
[0, 2, 0, 0]
[0, 0, 3, 0]
[0, 0, 0, 4]]
ข้อโต้แย้ง:
- ขอบเขต: วัตถุ ขอบเขต
- เส้นทแยงมุม: อันดับ k เทนเซอร์ โดยที่ k มีค่าสูงสุด 1
ผลตอบแทน:
คุณลักษณะสาธารณะ
งานสาธารณะ
โหนด
::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::Diag Class Reference\n\ntensorflow::ops::Diag\n=====================\n\n`#include \u003carray_ops.h\u003e`\n\nReturns a diagonal tensor with a given diagonal values.\n\nSummary\n-------\n\nGiven a `diagonal`, this operation returns a tensor with the `diagonal` and everything else padded with zeros. The diagonal is computed as follows:\n\nAssume `diagonal` has dimensions \\[D1,..., Dk\\], then the output is a tensor of rank 2k with dimensions \\[D1,..., Dk, D1,..., Dk\\] where:\n\n`output[i1,..., ik, i1,..., ik] = diagonal[i1, ..., ik]` and 0 everywhere else.\n\nFor example:\n\n\n```text\n# 'diagonal' is [1, 2, 3, 4]\ntf.diag(diagonal) ==\u003e [[1, 0, 0, 0]\n [0, 2, 0, 0]\n [0, 0, 3, 0]\n [0, 0, 0, 4]]\n```\n\n\u003cbr /\u003e\n\nArguments:\n\n- scope: A [Scope](/versions/r2.2/api_docs/cc/class/tensorflow/scope#classtensorflow_1_1_scope) object\n- diagonal: Rank k tensor where k is at most 1.\n\n\u003cbr /\u003e\n\nReturns:\n\n- [Output](/versions/r2.2/api_docs/cc/class/tensorflow/output#classtensorflow_1_1_output): The output tensor.\n\n\u003cbr /\u003e\n\n| ### Constructors and Destructors ||\n|---|---|\n| [Diag](#classtensorflow_1_1ops_1_1_diag_1a5beb111139305546f475c8687a35ce26)`(const ::`[tensorflow::Scope](/versions/r2.2/api_docs/cc/class/tensorflow/scope#classtensorflow_1_1_scope)` & scope, ::`[tensorflow::Input](/versions/r2.2/api_docs/cc/class/tensorflow/input#classtensorflow_1_1_input)` diagonal)` ||\n\n| ### Public attributes ||\n|----------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------|\n| [operation](#classtensorflow_1_1ops_1_1_diag_1a051fe6a94969df559f77f9da31685e59) | [Operation](/versions/r2.2/api_docs/cc/class/tensorflow/operation#classtensorflow_1_1_operation) |\n| [output](#classtensorflow_1_1ops_1_1_diag_1a0928ff530cf6fe0c4b3f4f1e6e1a419b) | `::`[tensorflow::Output](/versions/r2.2/api_docs/cc/class/tensorflow/output#classtensorflow_1_1_output) |\n\n| ### Public functions ||\n|----------------------------------------------------------------------------------------------------------------|------------------------|\n| [node](#classtensorflow_1_1ops_1_1_diag_1a53b2f11c3a488f759bd883f16f5bbbf2)`() const ` | `::tensorflow::Node *` |\n| [operator::tensorflow::Input](#classtensorflow_1_1ops_1_1_diag_1ac6d654e5b82ac6954ce4b60948da65d9)`() const ` | ` ` ` ` |\n| [operator::tensorflow::Output](#classtensorflow_1_1ops_1_1_diag_1ae8e07573b96ad7b6b69b9c4d4d4016d8)`() 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### Diag\n\n```gdscript\n Diag(\n const ::tensorflow::Scope & scope,\n ::tensorflow::Input diagonal\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```"]]