mindspore/docs/api/api_python/ops/mindspore.ops.L2Normalize.rst

34 lines
1.4 KiB
ReStructuredText
Raw Normal View History

2021-12-07 12:17:56 +08:00
mindspore.ops.L2Normalize
==========================
2021-12-21 18:09:08 +08:00
.. py:class:: mindspore.ops.L2Normalize(axis=0, epsilon=1e-4)
2021-12-07 12:17:56 +08:00
L2范数归一化算子。
该算子将对输入 `x` 在给定 `axis` 上的元素进行归一化。函数定义如下:
.. math::
2021-12-21 18:09:08 +08:00
\displaylines{{\text{output} = \frac{x}{\sqrt{\text{max}( \sum_{i}^{}\left | x_i \right | ^2, \epsilon)}}}}
2021-12-07 12:17:56 +08:00
其中 :math:`\epsilon` 表示 `epsilon` :math:`\sum_{i}^{}\left | x_i \right | ^2` 表示计算输入 `x` 在给定 `axis` 上元素的平方和。
2022-12-28 11:08:33 +08:00
.. note::
在Ascend上暂时不支持float64数据类型。
2022-07-26 10:27:56 +08:00
参数:
- **axis** (Union[list(int), tuple(int), int]) - 指定计算L2范数的轴。默认值0。
- **epsilon** (float) - 为了数值稳定性而引入的很小的浮点数。默认值1e-4。
输入:
2022-12-28 11:08:33 +08:00
- **x** (Tensor) - 计算归一化的输入。shape为 :math:`(N, *)` ,其中 :math:`*` 表示任意的附加维度数。数据类型必须为float16、float32和float64。
2022-07-26 10:27:56 +08:00
输出:
Tensorshape和数据类型与 `x` 的相同。
异常:
- **TypeError** - `axis` 不是list、tuple或int。
- **TypeError** - `epsilon` 不是float。
- **TypeError** - `x` 不是Tensor。
2022-12-28 11:08:33 +08:00
- **TypeError** - `x` 的数据类型不是float16、float32或float64。
2022-07-26 10:27:56 +08:00
- **ValueError** - `x` 的维度不大于0。