Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
dòng chảy căng:: ôi:: chất nền
#include <string_ops.h>
Trả về chuỗi con từ Tensor
của chuỗi.
Bản tóm tắt
Đối với mỗi chuỗi trong Tensor
đầu vào, hãy tạo một chuỗi con bắt đầu từ pos
chỉ mục với tổng độ dài là len
.
Nếu len
xác định một chuỗi con có thể vượt quá độ dài của chuỗi đầu vào thì càng nhiều ký tự càng tốt sẽ được sử dụng.
Vị pos
âm biểu thị khoảng cách trong chuỗi ngược lại tính từ điểm cuối.
Nếu pos
chỉ định một chỉ mục nằm ngoài phạm vi cho bất kỳ chuỗi đầu vào nào thì InvalidArgumentError
sẽ được đưa ra.
pos
và len
phải có hình dạng giống nhau, nếu không thì ValueError
sẽ xuất hiện khi tạo Op.
LƯU Ý : Substr
hỗ trợ phát sóng tối đa hai chiều. Tìm hiểu thêm về phát sóng tại đây
Ví dụ
Sử dụng vô hướng pos
và len
:
input = [b'Hello', b'World']
position = 1
length = 3
output = [b'ell', b'orl']
Sử dụng pos
và len
có hình dạng giống như 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']]
Phát sóng pos
và len
lên 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']]
Phát sóng input
lên pos
và len
:
input = b'thirteen'
position = [1, 5, 7]
length = [3, 2, 1]
output = [b'hir', b'ee', b'n']
Lập luận:
- phạm vi: Một đối tượng Phạm vi
- đầu vào: Tenor của dây
- pos: Vô hướng xác định vị trí của ký tự đầu tiên trong mỗi chuỗi con
- len: Vô hướng xác định số lượng ký tự cần bao gồm trong mỗi chuỗi con
Thuộc tính tùy chọn (xem Attrs
):
- đơn vị: Đơn vị được sử dụng để tạo chuỗi con. Một trong số:
"BYTE"
(để xác định vị trí và độ dài theo byte) hoặc "UTF8_CHAR"
(đối với các điểm mã Unicode được mã hóa UTF-8). Mặc định là "BYTE"
. Kết quả không được xác định nếu unit=UTF8_CHAR
và chuỗi input
không chứa UTF-8 hợp lệ về mặt cấu trúc.
Trả về:
Các hàm tĩnh công khai |
---|
Unit (StringPiece x) | |
Thuộc tính công khai
Chức năng công cộng
nút
::tensorflow::Node * node() const
operator::tensorflow::Input() const
toán tử::tenorflow::Đầu ra
operator::tensorflow::Output() const
Các hàm tĩnh công khai
Đơn vị
Attrs Unit(
StringPiece x
)
Trừ phi có lưu ý khác, nội dung của trang này được cấp phép theo Giấy phép ghi nhận tác giả 4.0 của Creative Commons và các mẫu mã lập trình được cấp phép theo Giấy phép Apache 2.0. Để biết thông tin chi tiết, vui lòng tham khảo Chính sách trang web của Google Developers. Java là nhãn hiệu đã đăng ký của Oracle và/hoặc các đơn vị liên kết với Oracle.
Cập nhật lần gần đây nhất: 2025-07-26 UTC.
[null,null,["Cập nhật lần gần đây nhất: 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```"]]