# TensorFlow函数：tf.substr

## tf.substr函数

``````tf.substr(
input,
pos,
len,
name=None
)``````

pos 和 len 必须具有相同的形状,否则在 Op 创建时会抛出一个 ValueError.

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

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

``````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']]``````

``````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 = b'thirteen'
position = [1, 5, 7]
length =   [3, 2, 1]

output = [b'hir', b'ee', b'n']``````

• input：一个 string 类型的 Tensor,strings 张量.
• pos：一个 Tensor,必须是以下类型之一：int32,int64,标量定义每个子字符串中第一个字符的位置.
• len：一个 Tensor,必须具有相同的类型pos,标量定义要包含在每个子字符串中的字符数.
• name：操作的名称(可选).

App下载