tensorflow::ops::Substr

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, then as many characters as possible are used.

If pos is negative or specifies a character index larger than 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:

```python input = [b'Hello', b'World'] position = 1 length = 3

output = [b'ell', b'orl'] ```

Using pos and len with same shape as input:

```python 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"] ```

Arguments:

  • 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

Returns:

Constructors and Destructors
Substr(const ::tensorflow::Scope & scope, ::tensorflow::Input input, ::tensorflow::Input pos, ::tensorflow::Input len)
Public attributes
output
Public functions
node() const
::tensorflow::Node *
operator::tensorflow::Input() const
operator::tensorflow::Output() const

Public attributes

output

::tensorflow::Output output

Public functions

Substr

 Substr(
  const ::tensorflow::Scope & scope,
  ::tensorflow::Input input,
  ::tensorflow::Input pos,
  ::tensorflow::Input len
)

node

::tensorflow::Node * node() const 

operator::tensorflow::Input

operator::tensorflow::Input() const 

operator::tensorflow::Output

operator::tensorflow::Output() const 

© 2017 The TensorFlow Authors. All rights reserved.
Licensed under the Creative Commons Attribution License 3.0.
Code samples licensed under the Apache 2.0 License.
https://www.tensorflow.org/api_docs/cc/class/tensorflow/ops/substr.html

在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号

意见反馈
返回顶部