ee.Dictionary.map

將演算法對應至字典。演算法應會採用 2 個引數,也就是現有字典中的鍵和對應的值,並傳回指定鍵的新值。如果演算法傳回空值,系統會捨棄金鑰。

用量傳回
Dictionary.map(baseAlgorithm)字典
引數類型詳細資料
這個:dictionary字典
baseAlgorithm演算法

範例

程式碼編輯器 (JavaScript)

// A dictionary (e.g. results of ee.Image.reduceRegion of an S2 image).
var dict = ee.Dictionary({
  B1: 182,
  B2: 219,
  B3: 443
});

/**
 * Convert S2 surface reflectance units to native scale.
 */
function scale(key, value) {
  return ee.Number(value).divide(1e4);
}

print('S2 surface reflectance in native units', dict.map(scale));

Python 設定

請參閱 Python 環境頁面,瞭解 Python API 和如何使用 geemap 進行互動式開發。

import ee
import geemap.core as geemap

Colab (Python)

# A dictionary (e.g. results of ee.Image.reduceRegion of an S2 image).
dic = ee.Dictionary({
    'B1': 182,
    'B2': 219,
    'B3': 443
})


def scale(key, value):
  """Convert S2 surface reflectance units to native scale."""
  return ee.Number(value).divide(1e4)

print('S2 surface reflectance in native units:', dic.map(scale).getInfo())