จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
เทนเซอร์โฟลว์:: ปฏิบัติการ:: ส่วนย่อย
#include <string_ops.h>
ส่งกลับสตริงย่อยจาก Tensor
ของสตริง
สรุป
สำหรับแต่ละสตริงในอินพุต Tensor
ให้สร้างสตริงย่อยเริ่มต้นที่ดัชนี pos
โดยมีความยาวรวมเป็น len
หาก len
กำหนดสตริงย่อยที่จะขยายเกินความยาวของสตริงอินพุต ให้ใช้อักขระให้ได้มากที่สุด
pos
ติดลบบ่งบอกถึงระยะห่างภายในสตริงถอยหลังจากจุดสิ้นสุด
หาก pos
ระบุดัชนีซึ่งอยู่นอกช่วงสำหรับสตริงอินพุตใดๆ แสดงว่า InvalidArgumentError
ถูกส่งออกไป
pos
และ len
ต้องมีรูปร่างเหมือนกัน ไม่เช่นนั้นจะมี ValueError
เกิดขึ้นในการสร้าง Op
หมายเหตุ : Substr
รองรับการออกอากาศสูงสุดสองมิติ เพิ่มเติมเกี่ยวกับการออกอากาศ ที่นี่
ตัวอย่าง
ใช้สเกลาร์ pos
และ len
:
input = [b'Hello', b'World']
position = 1
length = 3
output = [b'ell', b'orl']
การใช้ pos
และ len
ที่มีรูปร่างเหมือนกับ input
:
input = [[b'ten', b'eleven', b'twelve'],
[b'thirteen', b'fourteen', b'fifteen'],
[b'sixteen', b'seventeen', b'eighteen']]
position = [[1, 2, 3],
[1, 2, 3],
[1, 2, 3]]
length = [[2, 3, 4],
[4, 3, 2],
[5, 5, 5]]
output = [[b'en', b'eve', b'lve'],
[b'hirt', b'urt', b'te'],
[b'ixtee', b'vente', b'hteen']]
การออกอากาศ pos
และ len
ไปยัง input
:
input = [[b'ten', b'eleven', b'twelve'],
[b'thirteen', b'fourteen', b'fifteen'],
[b'sixteen', b'seventeen', b'eighteen'],
[b'nineteen', b'twenty', b'twentyone']]
position = [1, 2, 3]
length = [1, 2, 3]
output = [[b'e', b'ev', b'lve'],
[b'h', b'ur', b'tee'],
[b'i', b've', b'hte'],
[b'i', b'en', b'nty']]
กำลังออกอากาศ input
ไปยัง pos
และ len
:
input = b'thirteen'
position = [1, 5, 7]
length = [3, 2, 1]
output = [b'hir', b'ee', b'n']
ข้อโต้แย้ง:
- ขอบเขต: วัตถุ ขอบเขต
- อินพุต: เทนเซอร์ ของสตริง
- pos: สเกลาร์กำหนดตำแหน่งของอักขระตัวแรกในแต่ละสตริงย่อย
- len: สเกลาร์กำหนดจำนวนอักขระที่จะรวมในแต่ละสตริงย่อย
แอ็ตทริบิวต์ทางเลือก (ดู Attrs
):
- unit: หน่วยที่ใช้สร้างสตริงย่อย หนึ่งใน:
"BYTE"
(สำหรับการกำหนดตำแหน่งและความยาวด้วยไบต์) หรือ "UTF8_CHAR"
(สำหรับจุดโค้ด Unicode ที่เข้ารหัส UTF-8) ค่าเริ่มต้นคือ "BYTE"
ผลลัพธ์ไม่ได้ถูกกำหนดไว้หาก unit=UTF8_CHAR
และสตริง input
ไม่มี UTF-8 ที่ถูกต้องเชิงโครงสร้าง
ผลตอบแทน:
ฟังก์ชันคงที่สาธารณะ |
---|
Unit (StringPiece x) | |
คุณลักษณะสาธารณะ
งานสาธารณะ
โหนด
::tensorflow::Node * node() const
operator::tensorflow::Input() const
ตัวดำเนินการ::tensorflow::เอาต์พุต
operator::tensorflow::Output() const
ฟังก์ชันคงที่สาธารณะ
หน่วย
Attrs Unit(
StringPiece x
)
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-07-26 UTC
[null,null,["อัปเดตล่าสุด 2025-07-26 UTC"],[],[],null,["# tensorflow::ops::Substr Class Reference\n\ntensorflow::ops::Substr\n=======================\n\n`#include \u003cstring_ops.h\u003e`\n\nReturn substrings from [Tensor](/versions/r2.0/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor) of strings.\n\nSummary\n-------\n\nFor each string in the input [Tensor](/versions/r2.0/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor), creates a substring starting at index `pos` with a total length of `len`.\n\nIf `len` defines a substring that would extend beyond the length of the input string, then as many characters as possible are used.\n\nA negative `pos` indicates distance within the string backwards from the end.\n\nIf `pos` specifies an index which is out of range for any of the input strings, then an `InvalidArgumentError` is thrown.\n\n`pos` and `len` must have the same shape, otherwise a `ValueError` is thrown on Op creation.\n\n*NOTE* : [Substr](/versions/r2.0/api_docs/cc/class/tensorflow/ops/substr#classtensorflow_1_1ops_1_1_substr) supports broadcasting up to two dimensions. More about broadcasting [here](http://docs.scipy.org/doc/numpy/user/basics.broadcasting.html)\n\n*** ** * ** ***\n\n\u003cbr /\u003e\n\nExamples\n\nUsing scalar `pos` and `len`:\n\n\n```text\ninput = [b'Hello', b'World']\nposition = 1\nlength = 3\n```\n\n\u003cbr /\u003e\n\n\n```text\noutput = [b'ell', b'orl']\n```\n\n\u003cbr /\u003e\n\nUsing `pos` and `len` with same shape as `input`:\n\n\n```text\ninput = [[b'ten', b'eleven', b'twelve'],\n [b'thirteen', b'fourteen', b'fifteen'],\n [b'sixteen', b'seventeen', b'eighteen']]\nposition = [[1, 2, 3],\n [1, 2, 3],\n [1, 2, 3]]\nlength = [[2, 3, 4],\n [4, 3, 2],\n [5, 5, 5]]\n```\n\n\u003cbr /\u003e\n\n\n```text\noutput = [[b'en', b'eve', b'lve'],\n [b'hirt', b'urt', b'te'],\n [b'ixtee', b'vente', b'hteen']]\n```\n\n\u003cbr /\u003e\n\nBroadcasting `pos` and `len` onto `input`:\n\n\n```text\ninput = [[b'ten', b'eleven', b'twelve'],\n [b'thirteen', b'fourteen', b'fifteen'],\n [b'sixteen', b'seventeen', b'eighteen'],\n [b'nineteen', b'twenty', b'twentyone']]\nposition = [1, 2, 3]\nlength = [1, 2, 3]\n```\n\n\u003cbr /\u003e\n\n\n```text\noutput = [[b'e', b'ev', b'lve'],\n [b'h', b'ur', b'tee'],\n [b'i', b've', b'hte'],\n [b'i', b'en', b'nty']]\n```\n\n\u003cbr /\u003e\n\nBroadcasting `input` onto `pos` and `len`:\n\n\n```text\ninput = b'thirteen'\nposition = [1, 5, 7]\nlength = [3, 2, 1]\n```\n\n\u003cbr /\u003e\n\n\n```text\noutput = [b'hir', b'ee', b'n']\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- input: [Tensor](/versions/r2.0/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor) of strings\n- pos: Scalar defining the position of first character in each substring\n- len: Scalar defining the number of characters to include in each substring\n\n\u003cbr /\u003e\n\nOptional attributes (see [Attrs](/versions/r2.0/api_docs/cc/struct/tensorflow/ops/substr/attrs#structtensorflow_1_1ops_1_1_substr_1_1_attrs)):\n\n- unit: The unit that is used to create the substring. One of: `\"BYTE\"` (for defining position and length by bytes) or `\"UTF8_CHAR\"` (for the UTF-8 encoded Unicode code points). The default is `\"BYTE\"`. Results are undefined if `unit=UTF8_CHAR` and the `input` strings do not contain structurally valid UTF-8.\n\n\u003cbr /\u003e\n\nReturns:\n\n- [Output](/versions/r2.0/api_docs/cc/class/tensorflow/output#classtensorflow_1_1_output): [Tensor](/versions/r2.0/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor) of substrings\n\n\u003cbr /\u003e\n\n| ### Constructors and Destructors ||\n|---|---|\n| [Substr](#classtensorflow_1_1ops_1_1_substr_1ac4ec231f379a3a957a1ba6c388900d2e)`(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)` input, ::`[tensorflow::Input](/versions/r2.0/api_docs/cc/class/tensorflow/input#classtensorflow_1_1_input)` pos, ::`[tensorflow::Input](/versions/r2.0/api_docs/cc/class/tensorflow/input#classtensorflow_1_1_input)` len)` ||\n| [Substr](#classtensorflow_1_1ops_1_1_substr_1ad8326181a5399cf82aef5d7e4d9b925b)`(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)` input, ::`[tensorflow::Input](/versions/r2.0/api_docs/cc/class/tensorflow/input#classtensorflow_1_1_input)` pos, ::`[tensorflow::Input](/versions/r2.0/api_docs/cc/class/tensorflow/input#classtensorflow_1_1_input)` len, const `[Substr::Attrs](/versions/r2.0/api_docs/cc/struct/tensorflow/ops/substr/attrs#structtensorflow_1_1ops_1_1_substr_1_1_attrs)` & attrs)` ||\n\n| ### Public attributes ||\n|------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------|\n| [operation](#classtensorflow_1_1ops_1_1_substr_1a5cebdcec605f165be72c6ccb0b0a7b6c) | [Operation](/versions/r2.0/api_docs/cc/class/tensorflow/operation#classtensorflow_1_1_operation) |\n| [output](#classtensorflow_1_1ops_1_1_substr_1a833ab93a8bd8153ad683227af6205edd) | `::`[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_substr_1a3a2b4eaf7158fcdda9d4b5e3012ed9c0)`() const ` | `::tensorflow::Node *` |\n| [operator::tensorflow::Input](#classtensorflow_1_1ops_1_1_substr_1ae833d53311bfbb74a3c86b93f99c5027)`() const ` | ` ` ` ` |\n| [operator::tensorflow::Output](#classtensorflow_1_1ops_1_1_substr_1a001cd1f5803fc422a0b6fa274ca5b0eb)`() const ` | ` ` ` ` |\n\n| ### Public static functions ||\n|------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------|\n| [Unit](#classtensorflow_1_1ops_1_1_substr_1a5ab53f27d3a07b25ad2b97cbaaa7747f)`(StringPiece x)` | [Attrs](/versions/r2.0/api_docs/cc/struct/tensorflow/ops/substr/attrs#structtensorflow_1_1ops_1_1_substr_1_1_attrs) |\n\n| ### Structs ||\n|-------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------|\n| [tensorflow::ops::Substr::Attrs](/versions/r2.0/api_docs/cc/struct/tensorflow/ops/substr/attrs) | Optional attribute setters for [Substr](/versions/r2.0/api_docs/cc/class/tensorflow/ops/substr#classtensorflow_1_1ops_1_1_substr). |\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### Substr\n\n```gdscript\n Substr(\n const ::tensorflow::Scope & scope,\n ::tensorflow::Input input,\n ::tensorflow::Input pos,\n ::tensorflow::Input len\n)\n``` \n\n### Substr\n\n```gdscript\n Substr(\n const ::tensorflow::Scope & scope,\n ::tensorflow::Input input,\n ::tensorflow::Input pos,\n ::tensorflow::Input len,\n const Substr::Attrs & attrs\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``` \n\nPublic static functions\n-----------------------\n\n### Unit\n\n```text\nAttrs Unit(\n StringPiece x\n)\n```"]]