ee.Array.accum
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
สะสมองค์ประกอบของอาร์เรย์ตามแกนที่ระบุ โดยตั้งค่าองค์ประกอบแต่ละรายการของผลลัพธ์เป็นการลดองค์ประกอบตามแกนนั้นจนถึงและรวมถึงตำแหน่งปัจจุบัน อาจใช้เพื่อสร้างผลรวมสะสม ลำดับที่เพิ่มขึ้นเรื่อยๆ ฯลฯ
การใช้งาน | การคืนสินค้า |
---|
Array.accum(axis, reducer) | อาร์เรย์ |
อาร์กิวเมนต์ | ประเภท | รายละเอียด |
---|
ดังนี้ array | อาร์เรย์ | อาร์เรย์ที่จะสะสม |
axis | จำนวนเต็ม | แกนที่จะใช้ในการสะสม |
reducer | Reducer, ค่าเริ่มต้น: null | ตัวลดเพื่อสะสมค่า ค่าเริ่มต้นคือ SUM เพื่อสร้างผลรวมสะสมของแต่ละเวกเตอร์ตามแกนที่ระบุ |
ตัวอย่าง
โปรแกรมแก้ไขโค้ด (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]
การตั้งค่า Python
ดูข้อมูลเกี่ยวกับ Python API และการใช้ geemap
เพื่อการพัฒนาแบบอินเทอร์แอกทีฟได้ที่หน้า
สภาพแวดล้อม Python
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()))
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-07-26 UTC
[null,null,["อัปเดตล่าสุด 2025-07-26 UTC"],[[["\u003cp\u003e\u003ccode\u003eArray.accum\u003c/code\u003e calculates the cumulative reduction of elements in an array along a specified axis.\u003c/p\u003e\n"],["\u003cp\u003eIt uses a reducer function, defaulting to sum, to determine how elements are accumulated.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eaxis\u003c/code\u003e argument defines the direction of accumulation (0 for rows, 1 for columns in 2D arrays).\u003c/p\u003e\n"],["\u003cp\u003eVarious reducers like \u003ccode\u003emin\u003c/code\u003e, \u003ccode\u003emax\u003c/code\u003e, \u003ccode\u003emean\u003c/code\u003e, and \u003ccode\u003eproduct\u003c/code\u003e can be used for different cumulative calculations.\u003c/p\u003e\n"],["\u003cp\u003eThe result is a new array with the same dimensions as the input, containing the accumulated values.\u003c/p\u003e\n"]]],[],null,["# ee.Array.accum\n\nAccumulates elements of an array along the given axis, by setting each element of the result to the reduction of elements along that axis up to and including the current position. May be used to make a cumulative sum, a monotonically increasing sequence, etc.\n\n\u003cbr /\u003e\n\n| Usage | Returns |\n|----------------------------------|---------|\n| Array.accum`(axis, `*reducer*`)` | Array |\n\n| Argument | Type | Details |\n|---------------|------------------------|------------------------------------------------------------------------------------------------------------------|\n| this: `array` | Array | Array to accumulate. |\n| `axis` | Integer | Axis along which to perform the accumulation. |\n| `reducer` | Reducer, default: null | Reducer to accumulate values. Default is SUM, to produce the cumulative sum of each vector along the given axis. |\n\nExamples\n--------\n\n### Code Editor (JavaScript)\n\n```javascript\nprint(ee.Array([-1]).accum(0)); // [-1]\nprint(ee.Array([-2, 1]).accum(0)); // [-2, -1]\nprint(ee.Array([-2, 1, 9]).accum(0)); // [-2, -1, 8]\n\n// accum over 2D arrays with different axes.\nprint(ee.Array([[1, 3], [5, 7]]).accum(0)); // [[1,3],[6,10]]\nprint(ee.Array([[1, 3], [5, 7]]).accum(1)); // [[1,4],[5,12]]\n\n// sum is the default reducer.\nprint(ee.Array([2, -2, 3, 1]).accum(0)); // [2,0,3,4]\nprint(ee.Array([2, -2, 3, 1]).accum(0, ee.Reducer.sum())); // [2,0,3,4]\n\n// Some example reducers.\nprint(ee.Array([2, -2, 3, 1]).accum(0, ee.Reducer.max())); // [2,2,3,3]\nprint(ee.Array([2, -2, 3, 1]).accum(0, ee.Reducer.mean())); // [2,0,1,1]\nprint(ee.Array([2, -2, 3, 1]).accum(0, ee.Reducer.min())); // [2,-2,-2,-2]\nprint(ee.Array([2, -2, 3]).accum(0, ee.Reducer.product())); // [2,-4,-12]\n```\nPython setup\n\nSee the [Python Environment](/earth-engine/guides/python_install) page for information on the Python API and using\n`geemap` for interactive development. \n\n```python\nimport ee\nimport geemap.core as geemap\n```\n\n### Colab (Python)\n\n```python\ndisplay(ee.Array([-1]).accum(0)) # [-1]\ndisplay(ee.Array([-2, 1]).accum(0)) # [-2, -1]\ndisplay(ee.Array([-2, 1, 9]).accum(0)) # [-2, -1, 8]\n\n# accum over 2D arrays with different axes.\ndisplay(ee.Array([[1, 3], [5, 7]]).accum(0)) # [[1, 3],[6, 10]]\ndisplay(ee.Array([[1, 3], [5, 7]]).accum(1)) # [[1, 4],[5, 12]]\n\n# sum is the default reducer.\ndisplay(ee.Array([2, -2, 3, 1]).accum(0)) # [2, 0, 3, 4]\n\n# [2, 0, 3, 4]\ndisplay(ee.Array([2, -2, 3, 1]).accum(0, ee.Reducer.sum()))\n\n\n# Some example reducers.\n# [2, 2, 3, 3]\ndisplay(ee.Array([2, -2, 3, 1]).accum(0, ee.Reducer.max()))\n\n\n# [2, 0, 1, 1]\ndisplay(ee.Array([2, -2, 3, 1]).accum(0, ee.Reducer.mean()))\n\n# [2, -2, -2, -2]\ndisplay(ee.Array([2, -2, 3, 1]).accum(0, ee.Reducer.min()))\n\n# [2, -4, -12]\ndisplay(ee.Array([2, -2, 3]).accum(0, ee.Reducer.product()))\n```"]]