根據 sep 將 input 的元素拆分為 RaggedTensor 。
用法
tf.strings.split(
input, sep=None, maxsplit=-1, name=None
)參數
-
input等級為N的字符串Tensor,要拆分的字符串。如果rank(input)靜態未知,則假定為1。 -
sep0-DstringTensor,分隔符字符串。 -
maxsplit一個int。如果maxsplit > 0,則結果拆分的限製。 -
name操作的名稱(可選)。
拋出
-
ValueError如果 sep 不是字符串。
返回
-
排名為
N+1的RaggedTensor,字符串根據分隔符拆分。
令 N 為 input 的大小(通常 N 為批量大小)。根據 sep 拆分 input 的每個元素,並返回包含拆分標記的 RaggedTensor。空標記被忽略。
例子:
tf.strings.split('hello world').numpy()
array([b'hello', b'world'], dtype=object)
tf.strings.split(['hello world', 'a b c'])
<tf.RaggedTensor [[b'hello', b'world'], [b'a', b'b', b'c']]>
如果給出sep,則連續的分隔符不會組合在一起,並被視為分隔空字符串。例如,"1<>2<><>3" 的 input 和 "<>" 的 sep 返回 ["1", "2", "", "3"] 。如果sep 為 None 或空字符串,則連續的空格被視為單個分隔符,如果字符串有前導或尾隨空格,則結果將在開頭或結尾不包含空字符串。
請注意,上述行為與 python 的 str.split 匹配。
相關用法
- Python tf.strings.substr用法及代碼示例
- Python tf.strings.strip用法及代碼示例
- Python tf.strings.reduce_join用法及代碼示例
- Python tf.strings.regex_full_match用法及代碼示例
- Python tf.strings.regex_replace用法及代碼示例
- Python tf.strings.length用法及代碼示例
- Python tf.strings.bytes_split用法及代碼示例
- Python tf.strings.as_string用法及代碼示例
- Python tf.strings.unsorted_segment_join用法及代碼示例
- Python tf.strings.lower用法及代碼示例
- Python tf.strings.upper用法及代碼示例
- Python tf.strings.unicode_decode_with_offsets用法及代碼示例
- Python tf.strings.join用法及代碼示例
- Python tf.strings.to_hash_bucket用法及代碼示例
- Python tf.strings.ngrams用法及代碼示例
- Python tf.strings.to_hash_bucket_strong用法及代碼示例
- Python tf.strings.unicode_decode用法及代碼示例
- Python tf.strings.unicode_encode用法及代碼示例
- Python tf.strings.format用法及代碼示例
- Python tf.strings.to_hash_bucket_fast用法及代碼示例
注:本文由純淨天空篩選整理自tensorflow.org大神的英文原創作品 tf.strings.split。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
