<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.21.0/tensorflow/python/ops/ragged/ragged_string_ops.py#L88-L183) |

Encodes each sequence of Unicode code points in `input` into a string.

#### View aliases


**Compat aliases for migration**

See
[Migration guide](https://www.tensorflow.org/guide/migrate) for
more details.

[`tf.compat.v1.strings.unicode_encode`](https://www.tensorflow.org/api_docs/python/tf/strings/unicode_encode)

<br />

    tf.strings.unicode_encode(
        input,
        output_encoding,
        errors='replace',
        replacement_char=65533,
        name=None
    )

### Used in the notebooks

| Used in the guide |
|---|
| - [Unicode strings](https://www.tensorflow.org/text/guide/unicode) - [Tokenizing with TF Text](https://www.tensorflow.org/text/guide/tokenizers) |

`result[i1...iN]` is the string formed by concatenating the Unicode
codepoints `input[1...iN, :]`, encoded using `output_encoding`.

<br />

<br />

<br />

| ## 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](https://www.unicode.org/glossary/#unicode_scalar_value) is encountered (optional). One of: <br /> * `'replace'`: Replace non-scalar-value with the `replacement_char`. (default) * `'ignore'`: Skip non-scalar-value . * `'strict'`: Raise an exception for any non-scalar-value. <br /> |
| `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). |

<br />

<br />

<br />

<br />

| ## Returns ||
|---|---|
| A `N` dimensional `string` tensor with shape `[D1...DN]`. ||

<br />

#### 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)