ee.Array.abs

  • The abs() function calculates the absolute value of each element in an input array.

  • It accepts an array as input and returns a new array with the absolute values of the original elements.

  • The function works on arrays of any dimensions, including nested arrays.

  • Both JavaScript and Python APIs support the abs() function.

On an element-wise basis, computes the absolute value of the input.

UsageReturns
Array.abs()Array
ArgumentTypeDetails
this: inputArrayThe input array.

Examples

Code Editor (JavaScript)

print(ee.Array([-1]).abs());  // [1]
print(ee.Array([-2, 0, 2]).abs());  // [2,0,2]
print(ee.Array([[-3.1, -2], [-1, 0]]).abs());  // [[3.1,2],[1,0]]

Python setup

See the Python Environment page for information on the Python API and using geemap for interactive development.

import ee
import geemap.core as geemap

Colab (Python)

display(ee.Array([-1]).abs())  # [1]
display(ee.Array([-2, 0, 2]).abs())  # [2, 0, 2]
display(ee.Array([[-3.1, -2], [-1, 0]]).abs())  # [[3.1, 2], [1, 0]]