[英]Pytorch equivalent of Numpy's logical_and and kin?
Pytorch 是否與 Numpy 的元素邏輯運算符( logical_and
、 logical_or
、 logical_not
和logical_xor
)等效? 在使用 CPU 時,在 Pytorch 張量上調用 Numpy 函數似乎工作得很好,甚至可以生成 Pytorch 張量作為輸出。 我主要問是因為我認為如果 pytorch 計算在 GPU 中運行,這不會很好地工作。
我已經查看了包含字符串“and”的所有函數的Pytorch 文檔索引,但似乎沒有一個相關。
PyTorch支持對ByteTensor
邏輯操作。 您可以使用&
, |
使用邏輯運算|
, ^
, ~
運算符如下:
>>> a = torch.ByteTensor([0, 1, 1, 0])
>>> b = torch.ByteTensor([1, 1, 0, 0])
>>> a & b # logical and
tensor([0, 1, 0, 0], dtype=torch.uint8)
>>> a | b # logical or
tensor([1, 1, 1, 0], dtype=torch.uint8)
>>> a ^ b # logical xor
tensor([1, 0, 1, 0], dtype=torch.uint8)
>>> ~a # logical not
tensor([1, 0, 0, 1], dtype=torch.uint8)
邏輯和:
a * b
邏輯或:
a + b
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.