---
title: "ClikaRT::ops::normalize"
sidebar_label: "normalize"
description: "L_p-normalizes input along dim: each slice is scaled to unit p-norm. \\[ \\mathrm{out} = \\frac{x}{\\max(\\lVert x \\rVert_p, \\varepsilon)} \\] input the input tensor; float dtype."
---

<!-- Generated by tools/doxygen2mdx from Doxygen XML. Do not edit. -->

<span class="api-kind api-kind--function">function</span>

## normalize() {#normalize}

<div class="api-signature">

[`Tensor`](../Tensor.md) **`normalize`**(<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`Tensor`](../Tensor.md) `input`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`Scalar`](../Scalar.md) `p` `=` `2.0`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;`int64_t` `dim` `=` `1`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;`std::optional<double>` `eps` `=` `std::nullopt`<br />
)

</div>

L\_p-normalizes `input` along `dim`: each slice is scaled to unit `p`-norm.

$$
\mathrm{out} = \frac{x}{\max(\lVert x \rVert_p, \varepsilon)}
$$

**Parameters**

- `input`: the input tensor; float dtype.
- `p`: the norm degree, an int or float [`Scalar`](../Scalar.md), kind-preserved; default 2.
- `dim`: the axis to normalize along; default 1.
- `eps`: divide-by-zero floor; `std::nullopt` selects 1e-12.

**Returns:** a new tensor, same shape and dtype as `input`.

**Throws**

- `ClikaRT::Error`: (`INVALID_ARGUMENT`) when `dim` is out of range.

<div class="api-declared">

Declared in `ClikaRT/compute/ops.h`, line 3775

</div>
