ee.Image.arrayAccum

는 결과 배열 픽셀의 각 요소를 지정된 축을 따라 해당 픽셀의 요소 감소로 설정하여 지정된 축을 따라 각 배열 픽셀의 요소를 누적합니다(축의 현재 위치까지 포함). 누적 합계, 단조롭게 증가하는 시퀀스 등을 만드는 데 사용할 수 있습니다.

사용반환 값
Image.arrayAccum(axis, reducer)이미지
인수유형세부정보
다음과 같은 경우: input이미지입력 이미지입니다.
axis정수누적 합계를 수행할 축입니다.
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]]