scalar

scalar(value: bool | int | float | complex, tensor: Tensor, *, dtype: dtype | None = None, layout: layout | None = None, device: device | None = None, requires_grad: bool | None = None) Tensor[source]

Returns a scalar tensor based on input with specified value.

Shortcut for full() with shape=().

Parameters:
  • value (bool | int | float | complex) – value with to fill the output.

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

  • 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.

Returns:

scalar tensor like tensor, modified by parameters, filled with value.

Return type:

torch.Tensor