공지사항:
2025년 4월 15일 전에 Earth Engine 사용을 위해 등록된 모든 비상업용 프로젝트는 Earth Engine 액세스를 유지하기 위해
비상업용 자격 요건을 인증해야 합니다.
ee.Image.arraySort
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
는 한 축을 따라 각 배열 픽셀의 요소를 정렬합니다.
사용 | 반환 값 |
---|
Image.arraySort(keys) | 이미지 |
인수 | 유형 | 세부정보 |
---|
다음과 같은 경우: image | 이미지 | 정렬할 배열 이미지입니다. |
keys | 이미지, 기본값: null | 정렬할 키(선택사항)입니다. 제공되지 않으면 값이 키로 사용됩니다. 키는 정렬할 방향을 결정하는 한 축을 따라 여러 요소를 가질 수 있습니다. |
예
코드 편집기 (JavaScript)
// A function to print arrays 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 with length 12.
var arrayImg1D = ee.Image([0, 10, 6, 5, 4, 7, 11, 1, 2, 9, 8, 3]).toArray();
print('1D array image (pixel)', sampArrImg(arrayImg1D));
// [0, 10, 6, 5, 4, 7, 11, 1, 2, 9, 8, 3]
// Sort the 1D array in ascending order.
var arrayImg1DSorted = arrayImg1D.arraySort();
print('1D array image sorted (pixel)', sampArrImg(arrayImg1DSorted));
// [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
// You can use another array image to control sorting. The order of values
// in the optional keys array translates to relative position in the input
// array. For example, here is a keys array image with non-sequential values in
// descending order, it will reverse the order of the input array; make the
// last position first and the first position last.
var keys1D = ee.Image([99, 98, 50, 45, 23, 18, 9, 8, 7, 5, 2, 0]).toArray();
print('1D array image keys (pixel)', sampArrImg(keys1D));
// [99, 98, 50, 45, 23, 18, 9, 8, 7, 5, 2, 0]
var arrayImg1DSortedKeys = arrayImg1D.arraySort(keys1D);
print('1D array image sorted by keys (pixel)', sampArrImg(arrayImg1DSortedKeys));
// [3, 8, 9, 2, 1, 11, 7, 4, 5, 6, 10, 0]
// To sort a 2D array, the keys array image is required.
// Create a 2D array image with 3 rows and 4 columns.
var arrayImg2D = arrayImg1D.arrayReshape(ee.Image([3, 4]).toArray(), 2);
print('2D array image (pixel)', sampArrImg(arrayImg2D));
// [[0, 10, 6, 5],
// [4, 7, 11, 1],
// [2, 9, 8, 3]]
// Only a single axis can be sorted at a time. Here, we reverse sort along rows.
// There are 4 elements in each row, so we construct an 1x4 array image.
var keys2Drows = ee.Image([3, 2, 1, 0]).toArray().toArray(1).arrayTranspose();
print('2D array image row keys (pixel)', sampArrImg(keys2Drows));
// [[3, 2, 1, 0]]
var arrayImg2DSortedRows = arrayImg2D.arraySort(keys2Drows);
print('2D array image sorted rows (pixel)', sampArrImg(arrayImg2DSortedRows));
// [[5, 6, 10, 0],
// [1, 11, 7, 4],
// [3, 8, 9, 2]]
// Reverse sort along columns, create a 3x1 keys array image with values in
// descending order.
var keys2Dcols = ee.Image([2, 1, 0]).toArray().toArray(1);
print('2D array image column keys (pixel)', sampArrImg(keys2Dcols));
// [[2],
// [1],
// [0]]
var arrayImg2DSortedCols = arrayImg2D.arraySort(keys2Dcols);
print('2D array image sorted cols (pixel)', sampArrImg(arrayImg2DSortedCols));
// [[2, 9, 8, 3],
// [4, 7, 11, 1],
// [0, 10, 6, 5]]
Python 설정
Python API 및 geemap
를 사용한 대화형 개발에 관한 자세한 내용은
Python 환경 페이지를 참고하세요.
import ee
import geemap.core as geemap
Colab (Python)
# A function to print arrays 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 with length 12.
array_img_1d = ee.Image([0, 10, 6, 5, 4, 7, 11, 1, 2, 9, 8, 3]).toArray()
print('1D array image (pixel):', samp_arr_img(array_img_1d).getInfo())
# [0, 10, 6, 5, 4, 7, 11, 1, 2, 9, 8, 3]
# Sort the 1D array in ascending order.
array_img_1d_sorted = array_img_1d.arraySort()
print('1D array image sorted (pixel):',
samp_arr_img(array_img_1d_sorted).getInfo())
# [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
# You can use another array image to control sorting. The order of values
# in the optional keys array translates to relative position in the input
# array. For example, here is a keys array image with non-sequential values in
# descending order, it will reverse the order of the input array; make the
# last position first and the first position last.
keys_1d = ee.Image([99, 98, 50, 45, 23, 18, 9, 8, 7, 5, 2, 0]).toArray()
print('1D array image keys (pixel):', samp_arr_img(keys_1d).getInfo())
# [99, 98, 50, 45, 23, 18, 9, 8, 7, 5, 2, 0]
array_img_1d_sorted_keys = array_img_1d.arraySort(keys_1d)
print('1D array image sorted by keys (pixel):',
samp_arr_img(array_img_1d_sorted_keys).getInfo())
# [3, 8, 9, 2, 1, 11, 7, 4, 5, 6, 10, 0]
# To sort a 2D array, the keys array image is required.
# Create a 2D array image with 3 rows and 4 columns.
array_img_2d = array_img_1d.arrayReshape(ee.Image([3, 4]).toArray(), 2)
print('2D array image (pixel):', samp_arr_img(array_img_2d).getInfo())
# [[0, 10, 6, 5],
# [4, 7, 11, 1],
# [2, 9, 8, 3]]
# Only a single axis can be sorted at a time. Here, we reverse sort along rows.
# There are 4 elements in each row, so we construct an 1x4 array image.
keys_2d_rows = ee.Image([3, 2, 1, 0]).toArray().toArray(1).arrayTranspose()
print('2D array image row keys (pixel):', samp_arr_img(keys_2d_rows).getInfo())
# [[3, 2, 1, 0]]
array_img_2d_sorted_rows = array_img_2d.arraySort(keys_2d_rows)
print('2D array image sorted rows (pixel):',
samp_arr_img(array_img_2d_sorted_rows).getInfo())
# [[5, 6, 10, 0],
# [1, 11, 7, 4],
# [3, 8, 9, 2]]
# Reverse sort along columns, create a 3x1 keys array image with values in
# descending order.
keys_2d_cols = ee.Image([2, 1, 0]).toArray().toArray(1)
print('2D array image column keys (pixel):',
samp_arr_img(keys_2d_cols).getInfo())
# [[2],
# [1],
# [0]]
array_img_2d_sorted_cols = array_img_2d.arraySort(keys_2d_cols)
print('2D array image sorted cols (pixel):',
samp_arr_img(array_img_2d_sorted_cols).getInfo())
# [[2, 9, 8, 3],
# [4, 7, 11, 1],
# [0, 10, 6, 5]]
달리 명시되지 않는 한 이 페이지의 콘텐츠에는 Creative Commons Attribution 4.0 라이선스에 따라 라이선스가 부여되며, 코드 샘플에는 Apache 2.0 라이선스에 따라 라이선스가 부여됩니다. 자세한 내용은 Google Developers 사이트 정책을 참조하세요. 자바는 Oracle 및/또는 Oracle 계열사의 등록 상표입니다.
최종 업데이트: 2025-07-26(UTC)
[null,null,["최종 업데이트: 2025-07-26(UTC)"],[[["\u003cp\u003e\u003ccode\u003eImage.arraySort()\u003c/code\u003e sorts elements within each pixel's array along a single axis, either ascending or descending.\u003c/p\u003e\n"],["\u003cp\u003eBy default, it sorts array elements in ascending order based on their values; an optional \u003ccode\u003ekeys\u003c/code\u003e argument allows for custom sorting based on another array image.\u003c/p\u003e\n"],["\u003cp\u003eWhen sorting 2D arrays, the \u003ccode\u003ekeys\u003c/code\u003e array image defines the sorting direction and order, allowing you to sort by rows or columns.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003ekeys\u003c/code\u003e array's dimensions determine the sorting axis: a 1xN array sorts along rows, and an Nx1 array sorts along columns of the input array image.\u003c/p\u003e\n"],["\u003cp\u003eThe values in the \u003ccode\u003ekeys\u003c/code\u003e array determine the relative positions of elements in the sorted output array.\u003c/p\u003e\n"]]],[],null,["# ee.Image.arraySort\n\nSorts elements of each array pixel along one axis.\n\n\u003cbr /\u003e\n\n| Usage | Returns |\n|-----------------------------|---------|\n| Image.arraySort`(`*keys*`)` | Image |\n\n| Argument | Type | Details |\n|---------------|----------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| this: `image` | Image | Array image to sort. |\n| `keys` | Image, default: null | Optional keys to sort by. If not provided, the values are used as the keys. The keys can only have multiple elements along one axis, which determines the direction to sort in. |\n\nExamples\n--------\n\n### Code Editor (JavaScript)\n\n```javascript\n// A function to print arrays 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 with length 12.\nvar arrayImg1D = ee.Image([0, 10, 6, 5, 4, 7, 11, 1, 2, 9, 8, 3]).toArray();\nprint('1D array image (pixel)', sampArrImg(arrayImg1D));\n// [0, 10, 6, 5, 4, 7, 11, 1, 2, 9, 8, 3]\n\n// Sort the 1D array in ascending order.\nvar arrayImg1DSorted = arrayImg1D.arraySort();\nprint('1D array image sorted (pixel)', sampArrImg(arrayImg1DSorted));\n// [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]\n\n// You can use another array image to control sorting. The order of values\n// in the optional keys array translates to relative position in the input\n// array. For example, here is a keys array image with non-sequential values in\n// descending order, it will reverse the order of the input array; make the\n// last position first and the first position last.\nvar keys1D = ee.Image([99, 98, 50, 45, 23, 18, 9, 8, 7, 5, 2, 0]).toArray();\nprint('1D array image keys (pixel)', sampArrImg(keys1D));\n// [99, 98, 50, 45, 23, 18, 9, 8, 7, 5, 2, 0]\nvar arrayImg1DSortedKeys = arrayImg1D.arraySort(keys1D);\nprint('1D array image sorted by keys (pixel)', sampArrImg(arrayImg1DSortedKeys));\n// [3, 8, 9, 2, 1, 11, 7, 4, 5, 6, 10, 0]\n\n// To sort a 2D array, the keys array image is required.\n// Create a 2D array image with 3 rows and 4 columns.\nvar arrayImg2D = arrayImg1D.arrayReshape(ee.Image([3, 4]).toArray(), 2);\nprint('2D array image (pixel)', sampArrImg(arrayImg2D));\n// [[0, 10, 6, 5],\n// [4, 7, 11, 1],\n// [2, 9, 8, 3]]\n\n// Only a single axis can be sorted at a time. Here, we reverse sort along rows.\n// There are 4 elements in each row, so we construct an 1x4 array image.\nvar keys2Drows = ee.Image([3, 2, 1, 0]).toArray().toArray(1).arrayTranspose();\nprint('2D array image row keys (pixel)', sampArrImg(keys2Drows));\n// [[3, 2, 1, 0]]\nvar arrayImg2DSortedRows = arrayImg2D.arraySort(keys2Drows);\nprint('2D array image sorted rows (pixel)', sampArrImg(arrayImg2DSortedRows));\n// [[5, 6, 10, 0],\n// [1, 11, 7, 4],\n// [3, 8, 9, 2]]\n\n// Reverse sort along columns, create a 3x1 keys array image with values in\n// descending order.\nvar keys2Dcols = ee.Image([2, 1, 0]).toArray().toArray(1);\nprint('2D array image column keys (pixel)', sampArrImg(keys2Dcols));\n// [[2],\n// [1],\n// [0]]\nvar arrayImg2DSortedCols = arrayImg2D.arraySort(keys2Dcols);\nprint('2D array image sorted cols (pixel)', sampArrImg(arrayImg2DSortedCols));\n// [[2, 9, 8, 3],\n// [4, 7, 11, 1],\n// [0, 10, 6, 5]]\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 arrays 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 with length 12.\narray_img_1d = ee.Image([0, 10, 6, 5, 4, 7, 11, 1, 2, 9, 8, 3]).toArray()\nprint('1D array image (pixel):', samp_arr_img(array_img_1d).getInfo())\n# [0, 10, 6, 5, 4, 7, 11, 1, 2, 9, 8, 3]\n\n# Sort the 1D array in ascending order.\narray_img_1d_sorted = array_img_1d.arraySort()\nprint('1D array image sorted (pixel):',\n samp_arr_img(array_img_1d_sorted).getInfo())\n# [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]\n\n# You can use another array image to control sorting. The order of values\n# in the optional keys array translates to relative position in the input\n# array. For example, here is a keys array image with non-sequential values in\n# descending order, it will reverse the order of the input array; make the\n# last position first and the first position last.\nkeys_1d = ee.Image([99, 98, 50, 45, 23, 18, 9, 8, 7, 5, 2, 0]).toArray()\nprint('1D array image keys (pixel):', samp_arr_img(keys_1d).getInfo())\n# [99, 98, 50, 45, 23, 18, 9, 8, 7, 5, 2, 0]\narray_img_1d_sorted_keys = array_img_1d.arraySort(keys_1d)\nprint('1D array image sorted by keys (pixel):',\n samp_arr_img(array_img_1d_sorted_keys).getInfo())\n# [3, 8, 9, 2, 1, 11, 7, 4, 5, 6, 10, 0]\n\n# To sort a 2D array, the keys array image is required.\n# Create a 2D array image with 3 rows and 4 columns.\narray_img_2d = array_img_1d.arrayReshape(ee.Image([3, 4]).toArray(), 2)\nprint('2D array image (pixel):', samp_arr_img(array_img_2d).getInfo())\n# [[0, 10, 6, 5],\n# [4, 7, 11, 1],\n# [2, 9, 8, 3]]\n\n# Only a single axis can be sorted at a time. Here, we reverse sort along rows.\n# There are 4 elements in each row, so we construct an 1x4 array image.\nkeys_2d_rows = ee.Image([3, 2, 1, 0]).toArray().toArray(1).arrayTranspose()\nprint('2D array image row keys (pixel):', samp_arr_img(keys_2d_rows).getInfo())\n# [[3, 2, 1, 0]]\narray_img_2d_sorted_rows = array_img_2d.arraySort(keys_2d_rows)\nprint('2D array image sorted rows (pixel):',\n samp_arr_img(array_img_2d_sorted_rows).getInfo())\n# [[5, 6, 10, 0],\n# [1, 11, 7, 4],\n# [3, 8, 9, 2]]\n\n# Reverse sort along columns, create a 3x1 keys array image with values in\n# descending order.\nkeys_2d_cols = ee.Image([2, 1, 0]).toArray().toArray(1)\nprint('2D array image column keys (pixel):',\n samp_arr_img(keys_2d_cols).getInfo())\n# [[2],\n# [1],\n# [0]]\narray_img_2d_sorted_cols = array_img_2d.arraySort(keys_2d_cols)\nprint('2D array image sorted cols (pixel):',\n samp_arr_img(array_img_2d_sorted_cols).getInfo())\n# [[2, 9, 8, 3],\n# [4, 7, 11, 1],\n# [0, 10, 6, 5]]\n```"]]