uniform

uniform(tensor: Tensor, *, shape: Sequence[int] | Size | None = None, dtype: dtype | None = None, layout: layout | None = None, device: device | None = None, requires_grad: bool | None = None, generator: Generator | None = None) Tensor[source]

Returns a tensor based on input filled with random values sampled uniformly.

Parameters:
  • tensor (torch.Tensor) – determines default output properties.

  • shape (Sequence[int] | torch.Size | None, optional) – overrides shape from tensor if specified. Defaults to None.

  • dtype (torch.dtype | None, optional) – overrides data type from tensor if specified. Defaults to None.

  • layout (torch.layout | None, optional) – overrides layout from tensor if specified. Defaults to None.

  • device (torch.device | None, optional) – overrides device from tensor if specified. Defaults to None.

  • requires_grad (bool | None, optional) – overrides gradient requirement from tensor if specified. Defaults to None.

  • generator (torch.Generator | None, optional) – pseudorandom number generator for sampling. Defaults to None.

Returns:

tensor like tensor, modified by parameters, with elements sampled from \(\mathcal{U}(0, 1)\).

Return type:

torch.Tensor

Note

To construct a scalar, set shape to ().

See also

See torch.rand() for the function which this extends.