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

torch.clamp()的作用把input的数据,夹逼到[min,max]之间

input:输入数据

min:最小数据

max:最大数据

如果input中的数据小于min,用min代替input中小于min的数据,

如果input中的数据大于max,用max代替input中大于max的数据


 

import torch as t
a=t.arange(8).view(2,4)
a

#tensor([[[0, 1, 2, 3]],

    [[4, 5, 6, 7]]])

t.clamp(a,min=3)

结果为:

tensor([[3, 3, 3, 3],
        [4, 5, 6, 7]])
posted @ 2020-09-10 18:36  SnailWorks  阅读(533)  评论(0)    收藏  举报