Announcement: On
November 13, 2024, all users will need to
use a Cloud project in order to access Earth Engine. After this date, continued individual access without a Cloud project will require
an exception.
ee.Array
Returns an array with the given coordinates.
Usage | Returns | ee.Array(values, pixelType) | Array |
Argument | Type | Details | values | Object | An existing array to cast, or a number/list of numbers/nested list of numbers of any depth to create an array from. For nested lists, all inner arrays at the same depth must have the same length and numbers may only be present at the deepest level. |
pixelType | PixelType, default: null | The type of each number in the values argument. If the pixel type is not provided, it will be inferred from the numbers in 'values'. If there aren't any numbers in 'values', this type must be provided. |
Examples
Code Editor (JavaScript)
// Requires an explicit PixelType if no data.
print(ee.Array([], ee.PixelType.int8())); // Empty []
print(ee.Array([[]], ee.PixelType.uint8())); // Empty [[]]
print(ee.Array([[], []], ee.PixelType.float())); // Empty [[], []]
// 1-D Arrays
print(ee.Array([0])); // [0]
print(ee.Array([0, 1])); // [0, 1]
// 2-D Arrays
print(ee.Array([[1]])); // [[1]]
print(ee.Array([[0, 1], [2, 3]])); // [[0,1],[2,3]]
// Arrays from ee.Number.
print(ee.Array([ee.Number(123).toUint8()])); // [123]
// Lists are useful ways to construct larger Arrays.
print(ee.Array(ee.List.sequence(0, 10, 2))); // // [0,2,4,6,8,10]
// Arrays can be used to make Arrays.
var array1D = ee.Array([1, 2, 3]);
// This is a cast.
print(ee.Array(array1D)); // [1,2,3]
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)
# Requires an explicit PixelType if no data.
print(ee.Array([], ee.PixelType.int8()).getInfo()) # Empty []
print(ee.Array([[]], ee.PixelType.uint8()).getInfo()) # Empty [[]]
print(ee.Array([[], []], ee.PixelType.float()).getInfo()) # Empty [[], []]
# 1-D Arrays
print(ee.Array([0]).getInfo()) # [0]
print(ee.Array([0, 1]).getInfo()) # [0, 1]
# 2-D Arrays
print(ee.Array([[1]]).getInfo()) # [[1]]
print(ee.Array([[0, 1], [2, 3]]).getInfo()) # [[0,1],[2,3]]
# Arrays from ee.Number.
print(ee.Array([ee.Number(123).toUint8()]).getInfo()) # [123]
# Lists are useful ways to construct larger Arrays.
print(ee.Array(ee.List.sequence(0, 10, 2)).getInfo()) # [0, 2, 4, 6, 8, 10]
# Arrays can be used to make Arrays.
array_one = ee.Array([1, 2, 3])
# This is a cast.
print(ee.Array(array_one).getInfo()) # [1, 2, 3]
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 2024-07-13 UTC.
[null,null,["Last updated 2024-07-13 UTC."],[[["`ee.Array` creates an Earth Engine Array object from existing arrays, numbers, lists, or nested lists of numbers."],["The optional `pixelType` argument specifies the data type of the array elements and is inferred if not provided."],["Nested lists used to construct the array must have consistent inner array lengths, with numbers only at the deepest level."],["`ee.Array` can also cast existing Earth Engine Arrays to a new Array object."],["Examples demonstrate constructing arrays from various inputs, including empty arrays, 1-D and 2-D arrays, and using `ee.List` and `ee.Number`."]]],[]]