scipp.to_unit(x, unit, *, copy=True)

Convert the variable to a different unit.


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.

Return type