將 input 中的每個 Unicode 代碼點序列編碼為字符串。
用法
tf.strings.unicode_encode(
input, output_encoding, errors='replace', replacement_char=65533,
name=None
)參數
-
input一個N+1維度的可能參差不齊的整數張量,形狀為[D1...DN, num_chars]。 -
output_encoding應該用於對每個代碼點序列進行編碼的 Unicode 編碼。可以是"UTF-8","UTF-16-BE"或"UTF-32-BE"。 -
errors指定遇到無效代碼點時的響應(可選)。之一:* `'replace'`:Replace invalid codepoint with the `replacement_char`. (default) * `'ignore'`:Skip invalid codepoints. * `'strict'`:Raise an exception for any invalid codepoint. -
replacement_charerrors='replace'時用於代替任何無效輸入的替換字符代碼點。可以使用任何有效的 unicode 代碼點。默認值是默認的 unicode 替換字符,即 0xFFFD (U+65533)。 -
name操作的名稱(可選)。
返回
-
一個
N維度string張量,形狀為[D1...DN]。
result[i1...iN] 是通過連接 Unicode 代碼點 input[1...iN,:] 形成的字符串,使用 output_encoding 編碼。
例子:
input = tf.ragged.constant(
[[71, 246, 246, 100, 110, 105, 103, 104, 116], [128522]])
print(unicode_encode(input, 'UTF-8'))
tf.Tensor([b'G\xc3\xb6\xc3\xb6dnight' b'\xf0\x9f\x98\x8a'],
shape=(2,), dtype=string)
相關用法
- Python tf.strings.unicode_decode_with_offsets用法及代碼示例
- Python tf.strings.unicode_decode用法及代碼示例
- Python tf.strings.unicode_split用法及代碼示例
- Python tf.strings.unicode_split_with_offsets用法及代碼示例
- Python tf.strings.unicode_script用法及代碼示例
- Python tf.strings.unicode_transcode用法及代碼示例
- Python tf.strings.unsorted_segment_join用法及代碼示例
- Python tf.strings.upper用法及代碼示例
- Python tf.strings.substr用法及代碼示例
- 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.lower用法及代碼示例
- Python tf.strings.split用法及代碼示例
- Python tf.strings.join用法及代碼示例
- Python tf.strings.to_hash_bucket用法及代碼示例
- Python tf.strings.ngrams用法及代碼示例
注:本文由純淨天空篩選整理自tensorflow.org大神的英文原創作品 tf.strings.unicode_encode。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
