PyTorch常用函數:torch.ge; torch.gt; torch.le; equal; eq


torch.ge
torch.ge(input, other, out=None) → Tensor
逐元素比較input和other,即是否 input>=otherinput>=other。

如果兩個張量有相同的形狀和元素值,則返回True ,否則 False。 第二個參數可以為一個數或與第一個參數相同形狀和類型的張量

參數:

input (Tensor) – 待對比的張量
other (Tensor or float) – 對比的張量或float值 out (Tensor, optional) – 輸出張量。必須為ByteTensor或者與第一個參數tensor相同類型。 返回值: 一個 torch.ByteTensor 張量,包含了每個位置的比較結果(是否 input >= other )。 返回類型: Tensor 例子: >>> torch.ge(torch.Tensor([[1, 2], [3, 4]]), torch.Tensor([[1, 1], [4, 4]])) 1 1 0 1 [torch.ByteTensor of size 2x2]
torch.gt
torch.gt(input, other, out=None) → Tensor
逐元素比較input和other , 即是否input>otherinput>other 如果兩個張量有相同的形狀和元素值,則返回True ,否則 False。 第二個參數可以為一個數或與第一個參數相同形狀和類型的張量

參數:

input (Tensor) – 要對比的張量
other (Tensor or float) – 要對比的張量或float值 out (Tensor, optional) – 輸出張量。必須為ByteTensor或者與第一個參數tensor相同類型。 返回值: 一個 torch.ByteTensor 張量,包含了每個位置的比較結果(是否 input >= other )。 返回類型: Tensor 例子: >>> torch.gt(torch.Tensor([[1, 2], [3, 4]]), torch.Tensor([[1, 1], [4, 4]])) 0 1 0 0 [torch.ByteTensor of size 2x2]
torch.le
torch.le(input, other, out=None) → Tensor
逐元素比較input和other , 即是否input<=otherinput<=other 第二個參數可以為一個數或與第一個參數相同形狀和類型的張量

參數:

input (Tensor) – 要對比的張量
other (Tensor or float ) – 對比的張量或float值 out (Tensor, optional) – 輸出張量。必須為ByteTensor或者與第一個參數tensor相同類型。 返回值: 一個 torch.ByteTensor 張量,包含了每個位置的比較結果(是否 input >= other )。 返回類型: Tensor 例子: >>> torch.le(torch.Tensor([[1, 2], [3, 4]]), torch.Tensor([[1, 1], [4, 4]])) 1 0 1 1 [torch.ByteTensor of size 2x2] torch.lt torch.lt(input, other, out=None) → Tensor 逐元素比較input和other , 即是否 input<otherinput<other 第二個參數可以為一個數或與第一個參數相同形狀和類型的張量 參數: input (Tensor) – 要對比的張量 other (Tensor or float ) – 對比的張量或float值 out (Tensor, optional) – 輸出張量。必須為ByteTensor或者與第一個參數tensor相同類型。 input: 一個 torch.ByteTensor 張量,包含了每個位置的比較結果(是否 tensor >= other )。 返回類型: Tensor 例子: >>> torch.lt(torch.Tensor([[1, 2], [3, 4]]), torch.Tensor([[1, 1], [4, 4]])) 0 0 1 0 [torch.ByteTensor of size 2x2]

a,b是兩個列表

a.equal(b)要求整個列表完全相同才是True

a.eq(b) 相同位置值相同則返回對應的True,返回的是一個列表


主要參考
https://blog.csdn.net/ljs_a/article/details/79848994
https://blog.csdn.net/qq_30468133/article/details/88667443


免責聲明!

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



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