shlogg · Early preview
Super Kai (Kazuya Ito) @superkai_kazuya

Understanding Where() In PyTorch For Conditional Operations

where() in PyTorch: Select elements based on condition. Args: condition (tensor of bool), input (tensor or scalar), other (tensor or scalar). Returns tensor with selected elements.

Buy Me a Coffee☕
*Memos:

My post explains count_nonzero().
My post explains argwhere() and nonzero().

where() can get the 0D or more D tensor of zero or more elements from two of the 0D or more D tensors of the zero or more elements selected either from input or other tensor, depending on condition as shown below:
*Memos:

where() can be used with torch or a tensor.
The 1st argument with torch or a tensor is condition(Required-Type:tensor of bool).
The 2nd argument(input) with torch or using a tensor(Required-Type:tensor or scalar of int, float, complex or bool):
*Memos:

torch must use inp...