find_true_position#
- sionna.phy.utils.find_true_position(bool_tensor: torch.Tensor, side: str = 'last', axis: int = -1) torch.Tensor[source]#
Finds the index of the first or last True value along the specified axis.
When no True value is present, it returns -1.
- Parameters:
bool_tensor (torch.Tensor) – Boolean tensor of any shape
side (str) –
'first'|'last'. If'first', the first True position is found, else the last.axis (int) – Axis along which to find the last True value
- Outputs:
position – Tensor of indices, containing the index of the first or last True value. Its shape is
bool_tensor.shapewith specifiedaxisremoved.
Examples
import torch from sionna.phy.utils import find_true_position x = torch.tensor([True, False, True, False, True]) print(find_true_position(x, side='first').item()) # 0 print(find_true_position(x, side='last').item()) # 4