食品网站建设的目的,西安的电商网站设计,可视化网站建设软件有哪些,apple开发者中心一、前言
嗯……最近遇到的奇奇怪怪的方法很多了#xff0c;学无止境啊#xff01;学不完啊#xff0c;根本学不完#xff01;本篇文章介绍四个方法#xff1a;torch.gt()、torch.ge()、torch.le()和torch.lt()方法#xff0c;由于这四个方法很相似#xff0c;所以放到…一、前言
嗯……最近遇到的奇奇怪怪的方法很多了学无止境啊学不完啊根本学不完本篇文章介绍四个方法torch.gt()、torch.ge()、torch.le()和torch.lt()方法由于这四个方法很相似所以放到一块解析了
函数作用torch.gt(intput, other)input othertorch.ge(intput, other)input ≥ othertorch.le(intput, other)input ≤ othertorch.lt(intput, other)input other
二、方法解析
由于方法类似我们只取一个进行详细解析其它三个只是比较的方式不同而已用法完全相同。
2.1 torch.gt() 按照惯例先对函数的参数及return做一个简单的解释。函数的作用元素级的比较input是否大于other如果inputother那input当前位置的元素为True否则当前位置的元素为False。 argument input要比较的tensorother可以是一个float类型的数或者是可以与input进行广播的tensor return 返回一个boolean类型的tensor 2.2 torch.ge()
作用判断input是否大于等于other。
2.3 torch.le()
作用判断input是否小于等于other。
2.4 torch.lt()
作用判断input是否小于other。
三、案例分析
3.1 torch.gt()
案例1
t torch.tensor([[1,2],[3,1]])
other 1
torch.gt(t, 1)运行结果
tensor([[False, True],[ True, False]])案例2
t torch.tensor([[1,2],[3,1]])
other torch.tensor([[2,1],[1,2]])
torch.gt(t, other)运行结果
tensor([[False, True],[ True, False]])3.2 torch.ge()
案例1
t torch.tensor([[1,2],[3,1]])
other 1
torch.ge(t, 1)运行结果
tensor([[True, True],[True, True]])案例2
t torch.tensor([[1,2],[3,1]])
other torch.tensor([[2,1],[1,2]])
torch.ge(t, other)运行结果
tensor([[False, True],[ True, False]])3.3 torch.le()
案例1
t torch.tensor([[1,2],[3,1]])
other 1
torch.le(t, 1)运行结果
tensor([[ True, False],[False, True]])案例2
t torch.tensor([[1,2],[3,1]])
other torch.tensor([[2,1],[1,2]])
torch.le(t, other)运行结果
tensor([[ True, False],[False, True]])3.4 torch.lt()
案例1
t torch.tensor([[1,2],[3,1]])
other 1
torch.lt(t, 1)tensor([[False, False],[False, False]])案例2
t torch.tensor([[1,2],[3,1]])
other torch.tensor([[2,1],[1,2]])
torch.lt(t, other)tensor([[ True, False],[False, True]])参考文献
[1]torch.gt()方法官方解释 [2]torch.ge()方法官方解释 [3]torch.le()方法官方解释 [4]torch.lt()方法官方解释
今天的你学会了吗