ee.Array.accum

Tích luỹ các phần tử của một mảng dọc theo trục đã cho, bằng cách đặt mỗi phần tử của kết quả thành mức giảm của các phần tử dọc theo trục đó cho đến và bao gồm cả vị trí hiện tại. Có thể dùng để tạo tổng tích luỹ, chuỗi tăng đơn điệu, v.v.

Cách sử dụngGiá trị trả về
Array.accum(axis, reducer)Mảng
Đối sốLoạiThông tin chi tiết
this: arrayMảngMảng cần tích luỹ.
axisSố nguyênTrục mà dọc theo đó sẽ thực hiện quá trình tích luỹ.
reducerTấm dốc, mặc định: nullHàm giảm để tích luỹ các giá trị. Giá trị mặc định là SUM, để tạo tổng tích luỹ của từng vectơ dọc theo trục đã cho.

Ví dụ

Trình soạn thảo mã (JavaScript)

print(ee.Array([-1]).accum(0));  // [-1]
print(ee.Array([-2, 1]).accum(0));  // [-2, -1]
print(ee.Array([-2, 1, 9]).accum(0));  // [-2, -1, 8]

// accum over 2D arrays with different axes.
print(ee.Array([[1, 3], [5, 7]]).accum(0));  // [[1,3],[6,10]]
print(ee.Array([[1, 3], [5, 7]]).accum(1));  // [[1,4],[5,12]]

// sum is the default reducer.
print(ee.Array([2, -2, 3, 1]).accum(0));  // [2,0,3,4]
print(ee.Array([2, -2, 3, 1]).accum(0, ee.Reducer.sum()));  // [2,0,3,4]

// Some example reducers.
print(ee.Array([2, -2, 3, 1]).accum(0, ee.Reducer.max()));  // [2,2,3,3]
print(ee.Array([2, -2, 3, 1]).accum(0, ee.Reducer.mean()));  // [2,0,1,1]
print(ee.Array([2, -2, 3, 1]).accum(0, ee.Reducer.min()));  // [2,-2,-2,-2]
print(ee.Array([2, -2, 3]).accum(0, ee.Reducer.product()));  // [2,-4,-12]

Thiết lập Python

Hãy xem trang Môi trường Python để biết thông tin về API Python và cách sử dụng geemap cho quá trình phát triển tương tác.

import ee
import geemap.core as geemap

Colab (Python)

display(ee.Array([-1]).accum(0))  # [-1]
display(ee.Array([-2, 1]).accum(0))  # [-2, -1]
display(ee.Array([-2, 1, 9]).accum(0))  # [-2, -1, 8]

# accum over 2D arrays with different axes.
display(ee.Array([[1, 3], [5, 7]]).accum(0))  # [[1, 3],[6, 10]]
display(ee.Array([[1, 3], [5, 7]]).accum(1))  # [[1, 4],[5, 12]]

# sum is the default reducer.
display(ee.Array([2, -2, 3, 1]).accum(0))  # [2, 0, 3, 4]

# [2, 0, 3, 4]
display(ee.Array([2, -2, 3, 1]).accum(0, ee.Reducer.sum()))


# Some example reducers.
# [2, 2, 3, 3]
display(ee.Array([2, -2, 3, 1]).accum(0, ee.Reducer.max()))


# [2, 0, 1, 1]
display(ee.Array([2, -2, 3, 1]).accum(0, ee.Reducer.mean()))

# [2, -2, -2, -2]
display(ee.Array([2, -2, 3, 1]).accum(0, ee.Reducer.min()))

# [2, -4, -12]
display(ee.Array([2, -2, 3]).accum(0, ee.Reducer.product()))