Pytorch Torch Where
# PyTorch torch.where Function
* * *
[ Pytorch torch Reference Manual](https://example.com/pytorch/pytorch-torch-ref.html)
`torch.where` is a function in PyTorch used to return elements based on a condition.
### Function Definition
torch.where(condition, input, other)
* * *
## Usage Example
## Example
import torch
condition = torch.tensor([[True,False],[False,True]])
x = torch.tensor([[1,2],[3,4]])
y = torch.tensor([[10,20],[30,40]])
result = torch.where(condition, x, y)
print(result)
Output:
tensor([[ 1, 20], [30, 4]])
* * *
[ Pytorch torch Reference Manual](https://example.com/pytorch/pytorch-torch-ref.html)
YouTip