Restez organisé à l'aide des collections
Enregistrez et classez les contenus selon vos préférences.
flux tensoriel : : opérations : : Sous-titre
#include <string_ops.h>
Renvoie les sous-chaînes du Tensor
des chaînes.
Résumé
Pour chaque chaîne du Tensor
d'entrée, crée une sous-chaîne commençant à l'index pos
avec une longueur totale de len
.
Si len
définit une sous-chaîne qui s'étendrait au-delà de la longueur de la chaîne d'entrée, alors autant de caractères que possible sont utilisés.
Une pos
négative indique la distance à l'intérieur de la chaîne en arrière depuis la fin.
Si pos
spécifie un index hors plage pour l'une des chaînes d'entrée, alors une InvalidArgumentError
est levée.
pos
et len
doivent avoir la même forme, sinon une ValueError
est levée lors de la création de l'Op.
REMARQUE : Substr
prend en charge la diffusion jusqu'à deux dimensions. En savoir plus sur la diffusion ici
Exemples
Utilisation pos
et len
scalaires :
input = [b'Hello', b'World']
position = 1
length = 3
output = [b'ell', b'orl']
Utiliser pos
et len
avec la même forme que 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
et len
de diffusion sur 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
de diffusion sur pos
et len
:
input = b'thirteen'
position = [1, 5, 7]
length = [3, 2, 1]
output = [b'hir', b'ee', b'n']
Arguments :
- scope : un objet Scope
- entrée : Tenseur de chaînes
- pos : Scalaire définissant la position du premier caractère dans chaque sous-chaîne
- len : Scalaire définissant le nombre de caractères à inclure dans chaque sous-chaîne
Attributs facultatifs (voir Attrs
) :
- unit : unité utilisée pour créer la sous-chaîne. L'un des éléments suivants :
"BYTE"
(pour définir la position et la longueur en octets) ou "UTF8_CHAR"
(pour les points de code Unicode codés en UTF-8). La valeur par défaut est "BYTE"
. Les résultats ne sont pas définis si unit=UTF8_CHAR
et que les chaînes input
ne contiennent pas d'UTF-8 structurellement valide.
Retours :
Fonctions statiques publiques |
---|
Unit (StringPiece x) | |
Attributs publics
Fonctions publiques
nœud
::tensorflow::Node * node() const
operator::tensorflow::Input() const
opérateur :: tensorflow :: Sortie
operator::tensorflow::Output() const
Fonctions statiques publiques
Unité
Attrs Unit(
StringPiece x
)
Sauf indication contraire, le contenu de cette page est régi par une licence Creative Commons Attribution 4.0, et les échantillons de code sont régis par une licence Apache 2.0. Pour en savoir plus, consultez les Règles du site Google Developers. Java est une marque déposée d'Oracle et/ou de ses sociétés affiliées.
Dernière mise à jour le 2025/07/26 (UTC).
[null,null,["Dernière mise à jour le 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```"]]