random_tensor_from_values#

sionna.phy.utils.random_tensor_from_values(values: torch.Tensor | List[Any], shape: List[int] | torch.Size, dtype: torch.dtype | None = None) → torch.Tensor[source]#

Generates a tensor of the specified shape, with elements randomly sampled from the provided set of values.

Parameters:
  • values (torch.Tensor | List[Any]) – The set of values to sample from. The output is placed on the device of values, or on device for list inputs.

  • shape (List[int] | torch.Size) – The desired shape of the output tensor

  • dtype (torch.dtype | None) – Desired dtype of the output

Outputs:

tensor – A tensor with the specified shape, where each element is randomly selected from values

Examples

from sionna.phy.utils import random_tensor_from_values

values = [0, 10, 20]
shape = [2, 3]
print(random_tensor_from_values(values, shape).cpu().numpy())
# array([[ 0, 20,  0],
#        [10,  0, 20]], dtype=int32)