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

38 lines
1.7 KiB
ReStructuredText
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

mindspore.ops.clamp
====================
.. py:function:: mindspore.ops.clamp(x, min=None, max=None)
将输入Tensor的值裁剪到指定的最小值和最大值之间。
限制 :math:`x` 的范围,其最小值为 `min` ,最大值为 `max`
.. math::
out_i= \left\{
\begin{array}{align}
max & \text{ if } x_i\ge max \\
x_i & \text{ if } min \lt x_i \lt max \\
min & \text{ if } x_i \le min \\
\end{array}\right.
.. note::
- `min``max` 不能同时为None
-`min` 为None`max` 不为None时Tensor中大于 `max` 的元素会变为 `max`
-`min` 不为None`max` 为None时Tensor中小于 `min` 的元素会变为 `min`
-`min` 大于 `max`Tensor中所有元素的值会被置为 `max`
- `x``min``max` 的数据类型需支持隐式类型转换,且不能为布尔型。
参数:
- **x** (Union(Tensor, list[Tensor], tuple[Tensor])) - `clamp` 的输入类型为Tensor、Tensor的列表或元组。支持任意维度的Tensor。
- **min** (Union(Tensor, float, int)) - 指定最小值。默认值为None。
- **max** (Union(Tensor, float, int)) - 指定最大值。默认值为None。
返回:
Tensor、Tensor的列表或元组表示裁剪后的Tensor。其shape和数据类型和 `x` 相同。
异常:
- **ValueError** - 如果 `min``max` 都为None。
- **TypeError** - 如果 `x` 的数据类型不在Tensor、list[Tensor]或tuple[Tensor]中。
- **TypeError** - 如果 `min` 的数据类型不为None、Tensor、float或int。
- **TypeError** - 如果 `max` 的数据类型不为None、Tensor、float或int。