ee.Dictionary.toArray
Returns numeric values of a dictionary as an array. If no keys are specified, all values are returned in the natural ordering of the dictionary's keys. The default 'axis' is 0.
Usage | Returns |
---|
Dictionary.toArray(keys, axis) | Array |
Argument | Type | Details |
---|
this: dictionary | Dictionary | |
keys | List, default: null | |
axis | Integer, default: 0 | |
Examples
// A dictionary (e.g. results of ee.Image.reduceRegion of an S2 image).
var dict = ee.Dictionary({
B1: 182,
B2: 219,
B3: 443
});
print('Values for selected keys converted to ee.Array',
dict.toArray(['B1', 'B2']));
print('Values for all keys converted to ee.Array',
dict.toArray());
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
# A dictionary (e.g. results of ee.Image.reduceRegion of an S2 image).
dic = ee.Dictionary({
'B1': 182,
'B2': 219,
'B3': 443
})
print('Values for selected keys converted to ee.Array:',
dic.toArray(['B1', 'B2']).getInfo())
print('Values for all keys converted to ee.Array:',
dic.toArray().getInfo())
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."],[[["`toArray()` converts the numeric values of an Earth Engine Dictionary into an Earth Engine Array."],["Users can specify a list of keys to extract specific values or leave it empty to retrieve all values in the dictionary's key order."],["The method defaults to using axis 0 and allows specifying an alternative axis if needed."]]],["The `toArray()` method converts dictionary values into an array. It accepts an optional list of `keys` to specify which values to include; if omitted, all values are included in the dictionary's natural key order. An optional `axis` argument (defaulting to 0) can also be passed. The method returns an array of numeric values. The example shows how to use it, both to get the values from specified keys or all keys.\n"]]