将 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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
