公告:凡是在
2025 年 4 月 15 日前註冊使用 Earth Engine 的非商業專案,都必須
驗證非商業用途資格,才能繼續存取 Earth Engine。
ee.Array.mask
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
:從輸入陣列中切出每個位置,與指定遮罩陣列的非零元素平行,藉此建立子陣列。
引數 | 類型 | 詳細資料 |
---|
這個:input | 陣列 | 要遮蓋的陣列。 |
mask | 陣列 | 遮罩陣列。 |
範例
程式碼編輯器 (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 設定
請參閱
Python 環境頁面,瞭解 Python API 和如何使用 geemap
進行互動式開發。
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)) # []
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-07-26 (世界標準時間)。
[null,null,["上次更新時間:2025-07-26 (世界標準時間)。"],[[["\u003cp\u003e\u003ccode\u003eArray.mask()\u003c/code\u003e creates a new array by selecting elements from the input array where corresponding elements in the mask array are non-zero.\u003c/p\u003e\n"],["\u003cp\u003eThe input and mask arrays must have the same dimensions.\u003c/p\u003e\n"],["\u003cp\u003eZero values in the mask array effectively "hide" corresponding elements in the input array, resulting in their exclusion from the output.\u003c/p\u003e\n"],["\u003cp\u003eThis function is useful for filtering or selectively extracting data from arrays based on a criteria represented by the mask.\u003c/p\u003e\n"]]],[],null,["# ee.Array.mask\n\nCreates a subarray by slicing out each position in an input array that is parallel to a non-zero element of the given mask array.\n\n\u003cbr /\u003e\n\n| Usage | Returns |\n|--------------------|---------|\n| Array.mask`(mask)` | Array |\n\n| Argument | Type | Details |\n|---------------|-------|----------------|\n| this: `input` | Array | Array to mask. |\n| `mask` | Array | Mask array. |\n\nExamples\n--------\n\n### Code Editor (JavaScript)\n\n```javascript\nprint(ee.Array([1]).mask([0])); // []\nprint(ee.Array([1]).mask([1])); // [1]\n\nprint(ee.Array([0, 1, 2, 3]).mask([0, 4, -1, 1.2])); // [1,2,3]\n\nprint(ee.Array([[1, 2, 3, 4]]).mask([[0, 0, 0, 0]])); // [[]]\nprint(ee.Array([[1, 2, 3, 4]]).mask([[1, 0, 1, 1]])); // [[1,3,4]]\n\nvar array = ee.Array([[1], [2], [3], [4]]);\nprint(array.mask([[0], [0], [0], [0]])); // []\nprint(array.mask([[1], [0], [1], [1]])); // [[1],[3],[4]]\n\nvar empty = ee.Array([], ee.PixelType.int8());\nprint(empty.mask(empty)); // []\n```\nPython setup\n\nSee the [Python Environment](/earth-engine/guides/python_install) page for information on the Python API and using\n`geemap` for interactive development. \n\n```python\nimport ee\nimport geemap.core as geemap\n```\n\n### Colab (Python)\n\n```python\ndisplay(ee.Array([1]).mask([0])) # []\ndisplay(ee.Array([1]).mask([1])) # [1]\n\ndisplay(ee.Array([0, 1, 2, 3]).mask([0, 4, -1, 1.2])) # [1, 2, 3]\n\ndisplay(ee.Array([[1, 2, 3, 4]]).mask([[0, 0, 0, 0]])) # [[]]\ndisplay(ee.Array([[1, 2, 3, 4]]).mask([[1, 0, 1, 1]])) # [[1, 3, 4]]\n\narray = ee.Array([[1], [2], [3], [4]])\ndisplay(array.mask([[0], [0], [0], [0]])) # []\ndisplay(array.mask([[1], [0], [1], [1]])) # [[1], [3], [4]]\n\nempty = ee.Array([], ee.PixelType.int8())\ndisplay(empty.mask(empty)) # []\n```"]]