快捷方式

torch.logical_not

torch.logical_not(input, *, out=None) Tensor

計算給定輸入張量的逐元素邏輯 NOT。 如果未指定,則輸出張量將具有 bool dtype。 如果輸入張量不是布林張量,則將零視為 False,將非零視為 True

參數

input (Tensor) – 輸入張量。

關鍵字參數

out (Tensor, optional) – 輸出張量(可選)。

範例

>>> torch.logical_not(torch.tensor([True, False]))
tensor([False,  True])
>>> torch.logical_not(torch.tensor([0, 1, -10], dtype=torch.int8))
tensor([ True, False, False])
>>> torch.logical_not(torch.tensor([0., 1.5, -10.], dtype=torch.double))
tensor([ True, False, False])
>>> torch.logical_not(torch.tensor([0., 1., -10.], dtype=torch.double), out=torch.empty(3, dtype=torch.int16))
tensor([1, 0, 0], dtype=torch.int16)

文件

Access comprehensive developer documentation for PyTorch

View Docs

Tutorials

Get in-depth tutorials for beginners and advanced developers

View Tutorials

Resources

Find development resources and get your questions answered

View Resources