scipp.abs#

scipp.abs(x, *, out=None)#

Element-wise absolute value.

Parameters:
  • x (TypeVar(_T)) – Input data.

  • out (Variable | None, default: None) – Optional output buffer. Only supported if x is a scipp.Variable.

Raises:

scipp.DTypeError – If the dtype has no absolute value, e.g., if it is a string.

Returns:

TypeVar(_T) – The absolute values of the input.

See also

scipp.norm

Examples

Basic usage with negative values:

>>> import scipp as sc
>>> x = sc.array(dims=['x'], values=[-2.0, -1.0, 0.0, 1.0, 2.0], unit='m')
>>> sc.abs(x)
<scipp.Variable> (x: 5)    float64              [m]  [2, 1, ..., 1, 2]

Units are preserved in the output:

>>> x = sc.array(dims=['x'], values=[-5.0, -3.0, 3.0], unit='kg')
>>> sc.abs(x)
<scipp.Variable> (x: 3)    float64             [kg]  [5, 3, 3]