torch.ge()函数解读

匿名 (未验证) 提交于 2019-12-03 00:03:02
  • 函数作用
    torch.ge(a,b)比较a,b的大小,a为张量,b可以为和a相同形状的张量,也可以为一个常数。

  • 代码示例

>>> import torch >>> a=torch.Tensor([[1,2,3],[4,5,6]]) >>> a tensor([[1., 2., 3.],         [4., 5., 6.]]) >>> b=torch.Tensor([[2,2,2],[4,5,7]]) >>> b tensor([[2., 2., 2.],         [4., 5., 7.]]) >>> torch.ge(a,b)      #逐个元素比较 tensor([[0, 1, 1],         [1, 1, 0]], dtype=torch.uint8) >>> c=torch.randn(4,4) >>> c tensor([[ 0.3021,  0.5238, -1.2107,  1.3706],         [-0.0715, -0.1180,  0.2854,  0.2061],         [ 0.7414,  0.2233, -0.4926, -0.6218],         [-0.0471,  1.1931,  0.8465, -0.5087]]) >>> d=torch.randn(4,4) >>> d tensor([[-1.9698,  1.8576,  0.2773,  0.6412],         [ 1.0153,  0.5828,  0.8718, -0.1757],         [ 0.7880,  0.8339, -0.5220, -0.3703],         [ 1.3132,  1.4456,  0.7565, -1.1955]]) >>> torch.ge(c,d) tensor([[1, 0, 0, 1],         [0, 0, 0, 1],         [0, 0, 1, 0],         [0, 0, 1, 1]], dtype=torch.uint8) >>> torch.ge(d,1)               #和1比较大小 tensor([[0, 1, 0, 0],         [1, 0, 0, 0],         [0, 0, 0, 0],         [1, 1, 0, 0]], dtype=torch.uint8)  
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!