ee.Array.mask

Creates a subarray by slicing out each position in an input array that is parallel to a non-zero element of the given mask array.

UsageReturns
Array.mask(mask)Array
ArgumentTypeDetails
this: inputArrayArray to mask.
maskArrayMask array.

Examples

Code Editor (JavaScript)

print(ee.Array([1]).mask([0]));  // []
print(ee.Array([1]).mask([1]));  // [1]

print(ee.Array([0, 1, 2, 3]).mask([0, 4, -1, 1.2]));  // [1,2,3]

print(ee.Array([[1, 2, 3, 4]]).mask([[0, 0, 0, 0]]));  // [[]]
print(ee.Array([[1, 2, 3, 4]]).mask([[1, 0, 1, 1]]));  // [[1,3,4]]

var array = ee.Array([[1], [2], [3], [4]]);
print(array.mask([[0], [0], [0], [0]]));  // []
print(array.mask([[1], [0], [1], [1]]));  // [[1],[3],[4]]

var empty = ee.Array([], ee.PixelType.int8());
print(empty.mask(empty));  // []

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]).mask([0]))  # []
display(ee.Array([1]).mask([1]))  # [1]

display(ee.Array([0, 1, 2, 3]).mask([0, 4, -1, 1.2]))  # [1, 2, 3]

display(ee.Array([[1, 2, 3, 4]]).mask([[0, 0, 0, 0]]))  # [[]]
display(ee.Array([[1, 2, 3, 4]]).mask([[1, 0, 1, 1]]))  # [[1, 3, 4]]

array = ee.Array([[1], [2], [3], [4]])
display(array.mask([[0], [0], [0], [0]]))  # []
display(array.mask([[1], [0], [1], [1]]))  # [[1], [3], [4]]

empty = ee.Array([], ee.PixelType.int8())
display(empty.mask(empty))  # []