tf.strings.unicode_encode
Stay organized with collections
Save and categorize content based on your preferences.
Encodes each sequence of Unicode code points in input into a string.
tf.strings.unicode_encode(
input,
output_encoding,
errors='replace',
replacement_char=65533,
name=None
)
Used in the notebooks
result[i1...iN] is the string formed by concatenating the Unicode
codepoints input[1...iN, :], encoded using output_encoding.
Args |
input
|
An N+1 dimensional potentially ragged integer tensor with shape
[D1...DN, num_chars].
|
output_encoding
|
Unicode encoding that should be used to encode each
code point sequence. Can be "UTF-8", "UTF-16-BE", or "UTF-32-BE".
|
errors
|
Specifies the response when a code point that is not a Unicode
scalar value
is encountered (optional). One of:
* `'replace'`: Replace non-scalar-value with the
`replacement_char`. (default)
* `'ignore'`: Skip non-scalar-value .
* `'strict'`: Raise an exception for any non-scalar-value.
|
replacement_char
|
The replacement character to be used in place of
any invalid input when errors='replace'. Any Unicode scalar value may
be used. The default value is the default Unicode replacement character
which is 0xFFFD (U+65533).
|
name
|
A name for the operation (optional).
|
Returns |
A N dimensional string tensor with shape [D1...DN].
|
Example:
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)
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates. Some content is licensed under the numpy license.
Last updated 2026-10-31 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2026-10-31 UTC."],[],[]]