Premium problem45. Clamp Values

Easy Locked

Clamp every element of tensor x to the range [lo, hi]: values below lo become lo, values above hi become hi, and values already inside the range are left unchanged.

Input

x = tensor([-5.0000, -1.0000,  0.5000,  2.0000,  9.0000])
lo = 0.0
hi = 1.0

Output

tensor([0.0000, 0.0000, 0.5000, 1.0000, 1.0000])

Premium problem

This one's part of Premium. Unlock the full PyTorch track plus every other premium problem on the site.

Implement solve(...)