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.
Usage | Returns | Array.mask(mask) | Array |
Argument | Type | Details | this: input | Array | Array to mask. |
mask | Array | Mask 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)) # []
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2023-10-06 UTC.
[null,null,["Last updated 2023-10-06 UTC."],[[["`Array.mask()` creates a new array by selecting elements from the input array where corresponding elements in the mask array are non-zero."],["The input and mask arrays must have the same dimensions."],["Zero values in the mask array effectively \"hide\" corresponding elements in the input array, resulting in their exclusion from the output."],["This function is useful for filtering or selectively extracting data from arrays based on a criteria represented by the mask."]]],[]]