Stay organized with collections
Save and categorize content based on your preferences.
tensorflow::ops::Substr
#include <string_ops.h>
Return substrings from Tensor
of strings.
Summary
For each string in the input Tensor
, creates a substring starting at index pos
with a total length of len
.
If 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.
A negative pos
indicates distance within the string backwards from the end.
If pos
specifies an index which is out of range for any of the input strings, then an InvalidArgumentError
is thrown.
pos
and len
must have the same shape, otherwise a ValueError
is thrown on Op creation.
NOTE: Substr
supports broadcasting up to two dimensions. More about broadcasting here
Examples
Using scalar pos
and len
:
input = [b'Hello', b'World']
position = 1
length = 3
output = [b'ell', b'orl']
Using pos
and len
with same shape as 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']]
Broadcasting pos
and len
onto 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']]
Broadcasting input
onto pos
and len
:
input = b'thirteen'
position = [1, 5, 7]
length = [3, 2, 1]
output = [b'hir', b'ee', b'n']
Raises:
ValueError
: If the first argument cannot be converted to a Tensor of dtype string
.
InvalidArgumentError
: If indices are out of range.
ValueError
: If pos
and len
are not the same shape.
Args:
- scope: A Scope object
- input: Tensor of strings
- pos: Scalar defining the position of first character in each substring
- len: Scalar defining the number of characters to include in each substring
Optional attributes (see Attrs
):
- 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.
Returns:
Public static functions
|
Unit(StringPiece x)
|
|
Public attributes
Public functions
node
::tensorflow::Node * node() const
operator::tensorflow::Input() const
operator::tensorflow::Output
operator::tensorflow::Output() const
Public static functions
Unit
Attrs Unit(
StringPiece x
)
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates. Some content is licensed under the numpy license.
Last updated 2023-10-06 UTC.
[null,null,["Last updated 2023-10-06 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.14/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.14/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.14/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.14/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\nArgs:\n\n- scope: A [Scope](/versions/r2.14/api_docs/cc/class/tensorflow/scope#classtensorflow_1_1_scope) object\n- input: [Tensor](/versions/r2.14/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.14/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.14/api_docs/cc/class/tensorflow/output#classtensorflow_1_1_output): [Tensor](/versions/r2.14/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.14/api_docs/cc/class/tensorflow/scope#classtensorflow_1_1_scope)` & scope, ::`[tensorflow::Input](/versions/r2.14/api_docs/cc/class/tensorflow/input#classtensorflow_1_1_input)` input, ::`[tensorflow::Input](/versions/r2.14/api_docs/cc/class/tensorflow/input#classtensorflow_1_1_input)` pos, ::`[tensorflow::Input](/versions/r2.14/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.14/api_docs/cc/class/tensorflow/scope#classtensorflow_1_1_scope)` & scope, ::`[tensorflow::Input](/versions/r2.14/api_docs/cc/class/tensorflow/input#classtensorflow_1_1_input)` input, ::`[tensorflow::Input](/versions/r2.14/api_docs/cc/class/tensorflow/input#classtensorflow_1_1_input)` pos, ::`[tensorflow::Input](/versions/r2.14/api_docs/cc/class/tensorflow/input#classtensorflow_1_1_input)` len, const `[Substr::Attrs](/versions/r2.14/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.14/api_docs/cc/class/tensorflow/operation#classtensorflow_1_1_operation) |\n| [output](#classtensorflow_1_1ops_1_1_substr_1a833ab93a8bd8153ad683227af6205edd) | `::`[tensorflow::Output](/versions/r2.14/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.14/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.14/api_docs/cc/struct/tensorflow/ops/substr/attrs) | Optional attribute setters for [Substr](/versions/r2.14/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```"]]