Code Editor (JavaScript)
var array1x6 = ee.Array([1, 2, 3, 4, 5, 6]);
print(array1x6.slice()); // [1,2,3,4,5,6]
print(array1x6.slice(0)); // [1,2,3,4,5,6]
print(array1x6.slice(0, 0, 6, 1)); // [1,2,3,4,5,6]
print(array1x6.slice(0, 0, 10, 1)); // [1,2,3,4,5,6]
print(array1x6.slice(0, 2)); // [3,4,5,6]
print(array1x6.slice(0, 5)); // [6]
print(array1x6.slice(0, 6)); // []
print(array1x6.slice(0, 0, 2)); // [1,2]
print(array1x6.slice(0, 0, 0)); // []
// Negative start and end.
print(array1x6.slice(0, 0, -3)); // [1,2,3]
print(array1x6.slice(0, -2, 6)); // [5,6]
print(array1x6.slice(0, 0, 6, 2)); // [1,3,5]
print(array1x6.slice(0, 0, 6, 3)); // [1,4]
print(array1x6.slice(0, 0, 6, 4)); // [1,5]
print(array1x6.slice(0, 0, 6, 6)); // [1]
print(array1x6.slice(0, 2, 6, 2)); // [3,5]
var array3x2 = ee.Array([[1, 2], [3, 4], [5, 6]]);
print(array3x2.slice()); // [[1,2],[3,4],[5,6]]
print(array3x2.slice(0)); // [[1,2],[3,4],[5,6]]
print(array3x2.slice(0, 0)); // [[1,2],[3,4],[5,6]]
print(array3x2.slice(0, 0, 1)); // [[1,2]]
print(array3x2.slice(0, 0, 2)); // [[1,2],[3,4]]
print(array3x2.slice(0, 0, 3, 1)); // [[1,2],[3,4],[5,6]]
print(array3x2.slice(0, 0, 3, 2)); // [[1,2],[5,6]]
print(array3x2.slice(0, 1, 3, 2)); // [[3,4]]
print(array3x2.slice(0, 0, 3, 3)); // [[1,2]]
print(array3x2.slice(1)); // [[1,2],[3,4],[5,6]]
print(array3x2.slice(1, 1)); // [[2],[4],[6]]
print(array3x2.slice(1, 0, 1)); // [[1],[3],[5]]
var empty = ee.Array([], ee.PixelType.int8());
print(empty.slice()); // []
print(empty.slice(0)); // []
print(empty.slice(0, 0, 0, 1)); // []
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)
array1x6 = ee.Array([1, 2, 3, 4, 5, 6])
display(array1x6.slice()) # [1, 2, 3, 4, 5, 6]
display(array1x6.slice(0)) # [1, 2, 3, 4, 5, 6]
display(array1x6.slice(0, 0, 6, 1)) # [1, 2, 3, 4, 5, 6]
display(array1x6.slice(0, 0, 10, 1)) # [1, 2, 3, 4, 5, 6]
display(array1x6.slice(0, 2)) # [3, 4, 5, 6]
display(array1x6.slice(0, 5)) # [6]
display(array1x6.slice(0, 6)) # []
display(array1x6.slice(0, 0, 2)) # [1, 2]
display(array1x6.slice(0, 0, 0)) # []
# Negative start and end.
display(array1x6.slice(0, 0, -3)) # [1, 2, 3]
display(array1x6.slice(0, -2, 6)) # [5, 6]
display(array1x6.slice(0, 0, 6, 2)) # [1, 3, 5]
display(array1x6.slice(0, 0, 6, 3)) # [1, 4]
display(array1x6.slice(0, 0, 6, 4)) # [1, 5]
display(array1x6.slice(0, 0, 6, 6)) # [1]
display(array1x6.slice(0, 2, 6, 2)) # [3, 5]
array3x2 = ee.Array([[1, 2], [3, 4], [5, 6]])
display(array3x2.slice()) # [[1, 2], [3, 4], [5, 6]]
display(array3x2.slice(0)) # [[1, 2], [3, 4], [5, 6]]
display(array3x2.slice(0, 0)) # [[1, 2],[3, 4],[5, 6]]
display(array3x2.slice(0, 0, 1)) # [[1, 2]]
display(array3x2.slice(0, 0, 2)) # [[1, 2], [3, 4]]
display(array3x2.slice(0, 0, 3, 1)) # [[1, 2], [3, 4], [5, 6]]
display(array3x2.slice(0, 0, 3, 2)) # [[1, 2], [5, 6]]
display(array3x2.slice(0, 1, 3, 2)) # [[3, 4]]
display(array3x2.slice(0, 0, 3, 3)) # [[1, 2]]
display(array3x2.slice(1)) # [[1, 2], [3, 4], [5, 6]]
display(array3x2.slice(1, 1)) # [[2], [4], [6]]
display(array3x2.slice(1, 0, 1)) # [[1], [3], [5]]
empty = ee.Array([], ee.PixelType.int8())
display(empty.slice()) # []
display(empty.slice(0)) # []
display(empty.slice(0, 0, 0, 1)) # []