torch.clamp() 函數


 

torch.clamp(input, min, max, out=None) → Tensor

將輸入input張量每個元素的夾緊到區間 [min,max][min,max],並返回結果到一個新張量。

操作定義如下:

      | min, if x_i < min
y_i = | x_i, if min <= x_i <= max
      | max, if x_i > max

 

a=torch.randint(low=0,high=10,size=(10,1))
print(a) a=torch.clamp(a,3,9) print(a)
tensor([[2],
        [1], [3], [0], [0], [4], [3], [6], [0], [5]]) tensor([[3], [3], [3], [3], [3], [4], [3], [6], [3], [5]])


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM