scipp.to_unit¶
- scipp.to_unit(x, unit, *, copy=True)¶
Convert the variable to a different unit.
Example:
var = 1.2 * sc.Unit('m') var_in_mm = sc.to_unit(var, unit='mm')
If the unit us unchanged and
copy
is False, the object is returned without making a deep copy.Raises an error 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
x (scipp._scipp.core.Variable) – Input variable.
unit (Union[scipp._scipp.core.Unit, str]) – Desired target unit.
copy (bool) – If False, return the input object if possible. If True, the function always returns a new object.
- Return type