python - Pytorch equivalent of Numpy's logical_and and kin ...
stackoverflow.com › questions › 54590661Feb 08, 2019 · You can use logical operations using &, |, ^, ~ operators as follows: >>> 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)
torch.logical_or — PyTorch 1.10.1 documentation
pytorch.org › docs › stabletorch.logical_or(input, other, *, out=None) → Tensor. Computes the element-wise logical OR of the given input tensors. Zeros are treated as False and nonzeros are treated as True. Parameters. input ( Tensor) – the input tensor. other ( Tensor) – the tensor to compute OR with. Keyword Arguments. out ( Tensor, optional) – the output tensor.
torch.logical_and — PyTorch 1.10.1 documentation
pytorch.org › docs › stabletorch.logical_and(input, other, *, out=None) → Tensor. Computes the element-wise logical AND of the given input tensors. Zeros are treated as False and nonzeros are treated as True. Parameters. input ( Tensor) – the input tensor. other ( Tensor) – the tensor to compute AND with. Keyword Arguments. out ( Tensor, optional) – the output tensor.