scipp.to_unit#
- scipp.to_unit(x, unit, *, copy=True)#
Convert the variable to a different unit.
Raises a
scipp.UnitError
if the input unit is not compatible with the provided unit, e.g., m cannot be converted to s.If the input dtype is an integer type or datetime64, the output is rounded and returned with the same dtype as the input.
- Parameters:
- Returns:
TypeVar
(VariableLikeType
,Variable
,DataArray
,Dataset
,DataGroup
[Any
]) – Input converted to the given unit.
Examples
>>> var = 1.2 * sc.Unit('m') >>> sc.to_unit(var, unit='mm') <scipp.Variable> () float64 [mm] 1200