Document feedback

Question document fragment

When a question document fragment contains a formula, it is displayed as a space.

Submission type
issue

It's a little complicated...

I'd like to ask someone.

PR

Just a small problem.

I can fix it online!

Please select the submission type

Problem type
Specifications and Common Mistakes

- Specifications and Common Mistakes:

- Misspellings or punctuation mistakes,incorrect formulas, abnormal display.

- Incorrect links, empty cells, or wrong formats.

- Chinese characters in English context.

- Minor inconsistencies between the UI and descriptions.

- Low writing fluency that does not affect understanding.

- Incorrect version numbers, including software package names and version numbers on the UI.

Usability

- Usability:

- Incorrect or missing key steps.

- Missing main function descriptions, keyword explanation, necessary prerequisites, or precautions.

- Ambiguous descriptions, unclear reference, or contradictory context.

- Unclear logic, such as missing classifications, items, and steps.

Correctness

- Correctness:

- Technical principles, function descriptions, supported platforms, parameter types, or exceptions inconsistent with that of software implementation.

- Incorrect schematic or architecture diagrams.

- Incorrect commands or command parameters.

- Incorrect code.

- Commands inconsistent with the functions.

- Wrong screenshots.

- Sample code running error, or running results inconsistent with the expectation.

Risk Warnings

- Risk Warnings:

- Lack of risk warnings for operations that may damage the system or important data.

Content Compliance

- Content Compliance:

- Contents that may violate applicable laws and regulations or geo-cultural context-sensitive words and expressions.

- Copyright infringement.

Please select the type of question

Problem description

Describe the bug so that we can quickly locate the problem.

mindspore.ops.clamp

View Source On Gitee
mindspore.ops.clamp(input, min=None, max=None)[source]

Clamp all elements of the input tensor within the range [min, max].

outi={max if inputimaxinputi if min<inputi<maxmin if inputimin

Note

  • min and max cannot be None at the same time;

  • If min is None , there is no lower bound.

  • if max is None , there is no upper bound.

  • If min is greater than max, the value of all elements in Tensor will be set to max;

Parameters
  • input (Tensor) – The input tensor.

  • min (Union(Tensor, float, int), optional) – The minimum value. Default None .

  • max (Union(Tensor, float, int), optional) – The maximum value. Default None .

Returns

Tensor

Supported Platforms:

Ascend GPU CPU

Examples

>>> import mindspore
>>> # case 1: `min` and `max` are integer
>>> input = mindspore.tensor([[1, 25, 5, 7], [4, 11, 6, 21]])
>>> mindspore.ops.clamp(input, 5, 20)
Tensor(shape=[2, 4], dtype=Int64, value=
[[ 5, 20,  5,  7],
 [ 5, 11,  6, 20]])
>>>
>>> # case 2: If `min` and `max` are tensors, their shapes need to be broadcastable with input.
>>> min = mindspore.tensor([2, 4, 6, 8])
>>> max = mindspore.tensor([10, 12, 14, 18])
>>> mindspore.ops.clamp(input, min, max)
Tensor(shape=[2, 4], dtype=Int64, value=
[[ 2, 12,  6,  8],
 [ 4, 11,  6, 18]])