Rate this Page
★ ★ ★ ★ ★

torch.clamp_max#

torch.clamp_max(input, max, *, out=None) → Tensor#

Clamps each element of input to be at most max. Equivalent to torch.clamp() with only max specified. If max is a tensor, input and max are broadcast to a common shape.

Parameters:
  • input (Tensor) – the input tensor.

  • max (Number or Tensor) – upper bound for each element.

Keyword Arguments:

out (Tensor, optional) – the output tensor.

Examples:

>>> a = torch.tensor([-1.0, 0.5, 2.0])
>>> torch.clamp_max(a, 1.0)
tensor([-1.0000,  0.5000,  1.0000])
>>> torch.clamp_max(a, torch.tensor([[0.0], [1.0]]))
tensor([[-1.0000,  0.0000,  0.0000],
        [-1.0000,  0.5000,  1.0000]])