コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
テンソルフロー::作戦::サブ文字列
#include <string_ops.h>
文字列のTensor
から部分文字列を返します。
まとめ
入力Tensor
の各文字列に対して、インデックスpos
から始まり全長len
の部分文字列を作成します。
len
入力文字列の長さを超える部分文字列を定義する場合、またはlen
が負の場合、できるだけ多くの文字が使用されます。
負のpos
文字列内の末尾から後方への距離を示します。
pos
入力文字列の範囲外のインデックスを指定した場合、 InvalidArgumentError
がスローされます。
pos
とlen
同じ形状でなければなりません。そうでない場合は、Op 作成時にValueError
がスローされます。
注: Substr
2 次元までのブロードキャストをサポートしています。放送について詳しくはこちら
例
スカラーpos
とlen
使用する場合:
input = [b'Hello', b'World']
position = 1
length = 3
output = [b'ell', b'orl']
input
と同じ形状のpos
とlen
使用する:
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']
発生するもの:
-
ValueError
: 最初の引数をdtype string
のTensorに変換できない場合。 -
InvalidArgumentError
: インデックスが範囲外の場合。 -
ValueError
: pos
とlen
同じ形状ではない場合。
引数:
- スコープ:スコープオブジェクト
- 入力: 文字列のテンソル
- pos: 各部分文字列の最初の文字の位置を定義するスカラー
- len: 各部分文字列に含める文字数を定義するスカラー
オプションの属性 ( Attrs
を参照):
- 単位: 部分文字列の作成に使用される単位。
"BYTE"
(バイト単位で位置と長さを定義する場合) または"UTF8_CHAR"
(UTF-8 でエンコードされた Unicode コード ポイントの場合) のいずれか。デフォルトは"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-27 UTC。
[null,null,["最終更新日 2025-07-27 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.3/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.3/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, or if `len` is negative, 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.3/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\nRaises:\n\n\n- `ValueError`: If the first argument cannot be converted to a [Tensor](/versions/r2.3/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor) of `dtype string`.\n- `InvalidArgumentError`: If indices are out of range.\n- `ValueError`: If `pos` and `len` are not the same shape.\n\n\u003cbr /\u003e\n\nArguments:\n\n- scope: A [Scope](/versions/r2.3/api_docs/cc/class/tensorflow/scope#classtensorflow_1_1_scope) object\n- input: [Tensor](/versions/r2.3/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.3/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.3/api_docs/cc/class/tensorflow/output#classtensorflow_1_1_output): [Tensor](/versions/r2.3/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.3/api_docs/cc/class/tensorflow/scope#classtensorflow_1_1_scope)` & scope, ::`[tensorflow::Input](/versions/r2.3/api_docs/cc/class/tensorflow/input#classtensorflow_1_1_input)` input, ::`[tensorflow::Input](/versions/r2.3/api_docs/cc/class/tensorflow/input#classtensorflow_1_1_input)` pos, ::`[tensorflow::Input](/versions/r2.3/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.3/api_docs/cc/class/tensorflow/scope#classtensorflow_1_1_scope)` & scope, ::`[tensorflow::Input](/versions/r2.3/api_docs/cc/class/tensorflow/input#classtensorflow_1_1_input)` input, ::`[tensorflow::Input](/versions/r2.3/api_docs/cc/class/tensorflow/input#classtensorflow_1_1_input)` pos, ::`[tensorflow::Input](/versions/r2.3/api_docs/cc/class/tensorflow/input#classtensorflow_1_1_input)` len, const `[Substr::Attrs](/versions/r2.3/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.3/api_docs/cc/class/tensorflow/operation#classtensorflow_1_1_operation) |\n| [output](#classtensorflow_1_1ops_1_1_substr_1a833ab93a8bd8153ad683227af6205edd) | `::`[tensorflow::Output](/versions/r2.3/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.3/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.3/api_docs/cc/struct/tensorflow/ops/substr/attrs) | Optional attribute setters for [Substr](/versions/r2.3/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```"]]