ee.Image.arrayAccum
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
สะสมองค์ประกอบของพิกเซลอาร์เรย์แต่ละรายการตามแกนที่ระบุ โดยการตั้งค่าองค์ประกอบแต่ละรายการของพิกเซลอาร์เรย์ผลลัพธ์เป็นการลดองค์ประกอบในพิกเซลนั้นตามแกนที่ระบุ จนถึงและรวมถึงตำแหน่งปัจจุบันบนแกน อาจใช้เพื่อสร้างผลรวมสะสม ลำดับที่เพิ่มขึ้นเรื่อยๆ ฯลฯ
การใช้งาน | การคืนสินค้า |
---|
Image.arrayAccum(axis, reducer) | รูปภาพ |
อาร์กิวเมนต์ | ประเภท | รายละเอียด |
---|
ดังนี้ input | รูปภาพ | รูปภาพที่ป้อน |
axis | จำนวนเต็ม | แกนที่จะใช้ในการหาผลรวมสะสม |
reducer | Reducer, ค่าเริ่มต้น: null | ตัวลดเพื่อสะสมค่า ค่าเริ่มต้นคือ SUM เพื่อสร้างผลรวมสะสมของแต่ละเวกเตอร์ตามแกนที่ระบุ |
ตัวอย่าง
โปรแกรมแก้ไขโค้ด (JavaScript)
// A function to print the array for a selected pixel in the following examples.
function sampArrImg(arrImg) {
var point = ee.Geometry.Point([-121, 42]);
return arrImg.sample(point, 500).first().get('array');
}
// Create a 1D array image.
var arrayImg1D = ee.Image([1, 2, 3]).toArray();
print('1D array image (pixel)', sampArrImg(arrayImg1D));
// [1, 2, 3]
// Perform accumulation procedures along axes using ee.Reducer functions.
// Here we calculate the cumulative sum along the 0-axis for a 1D array.
var accumSum1DAx0 = arrayImg1D.arrayAccum(0, ee.Reducer.sum());
print('Cumulative sum along 0-axis', sampArrImg(accumSum1DAx0));
// [1, 3, 6]
// Create a 2D 3x3 array image.
var arrayImg2D = ee.Image([1, 2, 3, 4, 5, 6, 7, 8, 9]).toArray()
.arrayReshape(ee.Image([3, 3]).toArray(), 2);
print('2D 3x3 array image (pixel)', sampArrImg(arrayImg2D));
// [[1, 2, 3],
// [4, 5, 6],
// [7, 8, 9]]
// Calculate the cumulative sum along the 0-axis for a 2D array.
var accumSum2DAx0 = arrayImg2D.arrayAccum(0, ee.Reducer.sum());
print('Cumulative sum along 0-axis', sampArrImg(accumSum2DAx0));
// [[ 1, 2, 3],
// [ 5, 7, 9],
// [12, 15, 18]]
// Calculate the cumulative sum along the 1-axis for a 2D array.
var accumSum2DAx1 = arrayImg2D.arrayAccum(1, ee.Reducer.sum());
print('Cumulative sum along 1-axis', sampArrImg(accumSum2DAx1));
// [[1, 3, 6],
// [4, 9, 15],
// [7, 15, 24]]
การตั้งค่า Python
ดูข้อมูลเกี่ยวกับ Python API และการใช้ geemap
เพื่อการพัฒนาแบบอินเทอร์แอกทีฟได้ที่หน้า
สภาพแวดล้อม Python
import ee
import geemap.core as geemap
Colab (Python)
# A function to print the array for a selected pixel in the following examples.
def samp_arr_img(arr_img):
point = ee.Geometry.Point([-121, 42])
return arr_img.sample(point, 500).first().get('array')
# Create a 1D array image.
array_img_1d = ee.Image([1, 2, 3]).toArray()
print('1D array image (pixel):', samp_arr_img(array_img_1d).getInfo())
# [1, 2, 3]
# Perform accumulation procedures along axes using ee.Reducer functions.
# Here we calculate the cumulative sum along the 0-axis for a 1D array.
accum_sum_1d_ax0 = array_img_1d.arrayAccum(0, ee.Reducer.sum())
print('Cumulative sum along 0-axis:', samp_arr_img(accum_sum_1d_ax0).getInfo())
# [1, 3, 6]
# Create a 2D 3x3 array image.
array_img_2d = ee.Image([1, 2, 3, 4, 5, 6, 7, 8, 9]).toArray().arrayReshape(
ee.Image([3, 3]).toArray(),
2)
print('2D 3x3 array image (pixel):', samp_arr_img(array_img_2d).getInfo())
# [[1, 2, 3],
# [4, 5, 6],
# [7, 8, 9]]
# Calculate the cumulative sum along the 0-axis for a 2D array.
accum_sum_2d_ax0 = array_img_2d.arrayAccum(0, ee.Reducer.sum())
print('Cumulative sum along 0-axis:', samp_arr_img(accum_sum_2d_ax0).getInfo())
# [[ 1, 2, 3],
# [ 5, 7, 9],
# [12, 15, 18]]
# Calculate the cumulative sum along the 1-axis for a 2D array.
accum_sum_2d_ax1 = array_img_2d.arrayAccum(1, ee.Reducer.sum())
print('Cumulative sum along 1-axis:', samp_arr_img(accum_sum_2d_ax1).getInfo())
# [[1, 3, 6],
# [4, 9, 15],
# [7, 15, 24]]
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-07-26 UTC
[null,null,["อัปเดตล่าสุด 2025-07-26 UTC"],[[["\u003cp\u003e\u003ccode\u003eImage.arrayAccum()\u003c/code\u003e calculates the cumulative reduction of elements within each pixel of an array image along a specified axis.\u003c/p\u003e\n"],["\u003cp\u003eIt uses a reducer (defaulting to sum) to determine how elements are accumulated, producing a new array image.\u003c/p\u003e\n"],["\u003cp\u003eThe axis argument specifies the direction of accumulation (0 for rows, 1 for columns in 2D arrays).\u003c/p\u003e\n"],["\u003cp\u003eThis function is useful for generating cumulative sums, monotonically increasing sequences, and other cumulative calculations within array images.\u003c/p\u003e\n"],["\u003cp\u003eIt's applicable to both 1D and multidimensional array images in Earth Engine.\u003c/p\u003e\n"]]],[],null,["# ee.Image.arrayAccum\n\nAccumulates elements of each array pixel along the given axis, by setting each element of the result array pixel to the reduction of elements in that pixel along the given axis, up to and including the current position on the axis. May be used to make a cumulative sum, a monotonically increasing sequence, etc.\n\n\u003cbr /\u003e\n\n| Usage | Returns |\n|---------------------------------------|---------|\n| Image.arrayAccum`(axis, `*reducer*`)` | Image |\n\n| Argument | Type | Details |\n|---------------|------------------------|------------------------------------------------------------------------------------------------------------------|\n| this: `input` | Image | Input image. |\n| `axis` | Integer | Axis along which to perform the cumulative sum. |\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\n// A function to print the array for a selected pixel in the following examples.\nfunction sampArrImg(arrImg) {\n var point = ee.Geometry.Point([-121, 42]);\n return arrImg.sample(point, 500).first().get('array');\n}\n\n// Create a 1D array image.\nvar arrayImg1D = ee.Image([1, 2, 3]).toArray();\nprint('1D array image (pixel)', sampArrImg(arrayImg1D));\n// [1, 2, 3]\n\n// Perform accumulation procedures along axes using ee.Reducer functions.\n// Here we calculate the cumulative sum along the 0-axis for a 1D array.\nvar accumSum1DAx0 = arrayImg1D.arrayAccum(0, ee.Reducer.sum());\nprint('Cumulative sum along 0-axis', sampArrImg(accumSum1DAx0));\n// [1, 3, 6]\n\n// Create a 2D 3x3 array image.\nvar arrayImg2D = ee.Image([1, 2, 3, 4, 5, 6, 7, 8, 9]).toArray()\n .arrayReshape(ee.Image([3, 3]).toArray(), 2);\nprint('2D 3x3 array image (pixel)', sampArrImg(arrayImg2D));\n// [[1, 2, 3],\n// [4, 5, 6],\n// [7, 8, 9]]\n\n// Calculate the cumulative sum along the 0-axis for a 2D array.\nvar accumSum2DAx0 = arrayImg2D.arrayAccum(0, ee.Reducer.sum());\nprint('Cumulative sum along 0-axis', sampArrImg(accumSum2DAx0));\n// [[ 1, 2, 3],\n// [ 5, 7, 9],\n// [12, 15, 18]]\n\n// Calculate the cumulative sum along the 1-axis for a 2D array.\nvar accumSum2DAx1 = arrayImg2D.arrayAccum(1, ee.Reducer.sum());\nprint('Cumulative sum along 1-axis', sampArrImg(accumSum2DAx1));\n// [[1, 3, 6],\n// [4, 9, 15],\n// [7, 15, 24]]\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\n# A function to print the array for a selected pixel in the following examples.\ndef samp_arr_img(arr_img):\n point = ee.Geometry.Point([-121, 42])\n return arr_img.sample(point, 500).first().get('array')\n\n# Create a 1D array image.\narray_img_1d = ee.Image([1, 2, 3]).toArray()\nprint('1D array image (pixel):', samp_arr_img(array_img_1d).getInfo())\n# [1, 2, 3]\n\n# Perform accumulation procedures along axes using ee.Reducer functions.\n# Here we calculate the cumulative sum along the 0-axis for a 1D array.\naccum_sum_1d_ax0 = array_img_1d.arrayAccum(0, ee.Reducer.sum())\nprint('Cumulative sum along 0-axis:', samp_arr_img(accum_sum_1d_ax0).getInfo())\n# [1, 3, 6]\n\n# Create a 2D 3x3 array image.\narray_img_2d = ee.Image([1, 2, 3, 4, 5, 6, 7, 8, 9]).toArray().arrayReshape(\n ee.Image([3, 3]).toArray(),\n 2)\nprint('2D 3x3 array image (pixel):', samp_arr_img(array_img_2d).getInfo())\n# [[1, 2, 3],\n# [4, 5, 6],\n# [7, 8, 9]]\n\n# Calculate the cumulative sum along the 0-axis for a 2D array.\naccum_sum_2d_ax0 = array_img_2d.arrayAccum(0, ee.Reducer.sum())\nprint('Cumulative sum along 0-axis:', samp_arr_img(accum_sum_2d_ax0).getInfo())\n# [[ 1, 2, 3],\n# [ 5, 7, 9],\n# [12, 15, 18]]\n\n# Calculate the cumulative sum along the 1-axis for a 2D array.\naccum_sum_2d_ax1 = array_img_2d.arrayAccum(1, ee.Reducer.sum())\nprint('Cumulative sum along 1-axis:', samp_arr_img(accum_sum_2d_ax1).getInfo())\n# [[1, 3, 6],\n# [4, 9, 15],\n# [7, 15, 24]]\n```"]]