<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/neural-structured-learning/blob/v1.4.0/neural_structured_learning/lib/utils.py#L25-L67) |

Normalizes the values in `tensor` with respect to a specified vector norm.

    nsl.lib.normalize(
        tensor, norm_type, epsilon=1e-06
    )

This op assumes that the first axis of `tensor` is the batch dimension, and
calculates the norm over all other axes. For example, if `tensor` is
`tf.constant(1.0, shape=[2, 3, 4])`, its L2 norm (calculated along all the
dimensions other than the first dimension) will be `[[sqrt(12)], [sqrt(12)]]`.
Hence, this tensor will be normalized by dividing by
`[[sqrt(12)], [sqrt(12)]]`.

Note that [`tf.norm`](https://www.tensorflow.org/api_docs/python/tf/norm) is not used here since it only allows the norm to be
calculated over one axis, not multiple axes.

<br />

<br />

<br />

| ## Args ||
|---|---|
| `tensor` | a tensor to be normalized. Can have any shape with the first axis being the batch dimension that will not be normalized across. |
| `norm_type` | one of [`nsl.configs.NormType`](https://www.tensorflow.org/neural_structured_learning/api_docs/python/nsl/configs/NormType), the type of vector norm. |
| `epsilon` | a lower bound value for the norm to avoid division by 0. |

<br />

<br />

<br />

<br />

| ## Returns ||
|---|---|
| A normalized tensor with the same shape and type as `tensor`. ||

<br />