语法

lt(小于 )是less than的缩写,即input<other
torch.lt(input, other, out=None) → Tensor

  • input:张量
  • other:一个数或者与input有相同形状的张量
  • 函数返回类型Tensor
  • le(小于等于)less equal
  • eq(等于)equal
  • gt(大于)greater than
  • ge(大于等于)greater equal

例子

1、other为一个数

In [33]: a = torch.tensor([[1, 2], [3, 4]])

In [34]: a
Out[34]:
tensor([[1, 2],
        [3, 4]])

In [35]: torch.lt(a, 3.5)
Out[35]:
tensor([[ True,  True],
        [ True, False]])

In [36]: a<3.5
Out[36]:
tensor([[ True,  True],
        [ True, False]])

2、other为input相同形状的张量

In [37]: b = torch.tensor([[1, 0], [3, 5]])

In [38]: torch.eq(a, b)
Out[38]:
tensor([[ True, False],
        [ True, False]])

In [39]: a
Out[39]:
tensor([[1, 2],
        [3, 4]])

In [40]: b
Out[40]:
tensor([[1, 0],
        [3, 5]])

注意:因为pytorch里面没有True或False,所以返回的元素为True或False的张量称为掩码。

本文参考连接:[https://blog.csdn.net/weixin_44928646/article/details/104628619]

Logo

有“AI”的1024 = 2048,欢迎大家加入2048 AI社区

更多推荐