ee.Image.arrayTranspose
Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Chuyển vị hai chiều của mỗi pixel mảng.
Cách sử dụng | Giá trị trả về |
---|
Image.arrayTranspose(axis1, axis2) | Hình ảnh |
Đối số | Loại | Thông tin chi tiết |
---|
this: input | Hình ảnh | Hình ảnh đầu vào. |
axis1 | Số nguyên, mặc định: 0 | Trục đầu tiên cần hoán đổi. |
axis2 | Số nguyên, mặc định: 1 | Trục thứ hai cần hoán đổi. |
Ví dụ
Trình soạn thảo mã (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 2D array image.
var arrayImg2D = ee.Image([0, 1, 2, 3, 4, 5]).toArray().arrayReshape(
ee.Image([2, 3]).toArray(), 2);
print('2D 2x3 array image (pixel)', sampArrImg(arrayImg2D));
// [[0, 1, 2],
// [3, 4, 5]]
// Swap 0-axis and 1-axis. Input is a 2x3 array, output will be 3x2.
var transposed = arrayImg2D.arrayTranspose();
print('Transposed (3x2) array image (pixel)', sampArrImg(transposed));
// [[0, 3],
// [1, 4],
// [2, 5]]
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)
# 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 2D array image.
array_img_2d = ee.Image([0, 1, 2, 3, 4, 5]).toArray().arrayReshape(
ee.Image([2, 3]).toArray(),
2
)
print('2D 2x3 array image (pixel):', samp_arr_img(array_img_2d).getInfo())
# [[0, 1, 2],
# [3, 4, 5]]
# Swap 0-axis and 1-axis. Input is a 2x3 array, output will be 3x2.
transposed = array_img_2d.arrayTranspose()
print('Transposed (3x2) array image (pixel):',
samp_arr_img(transposed).getInfo())
# [[0, 3],
# [1, 4],
# [2, 5]]
Trừ phi có lưu ý khác, nội dung của trang này được cấp phép theo Giấy phép ghi nhận tác giả 4.0 của Creative Commons và các mẫu mã lập trình được cấp phép theo Giấy phép Apache 2.0. Để biết thông tin chi tiết, vui lòng tham khảo Chính sách trang web của Google Developers. Java là nhãn hiệu đã đăng ký của Oracle và/hoặc các đơn vị liên kết với Oracle.
Cập nhật lần gần đây nhất: 2025-07-26 UTC.
[null,null,["Cập nhật lần gần đây nhất: 2025-07-26 UTC."],[[["\u003cp\u003e\u003ccode\u003eImage.arrayTranspose()\u003c/code\u003e transposes two dimensions of each array pixel within an image.\u003c/p\u003e\n"],["\u003cp\u003eBy default, it swaps the first (axis 0) and second (axis 1) dimensions of the array, effectively transposing a 2D array.\u003c/p\u003e\n"],["\u003cp\u003eUsers can specify which axes to swap using the \u003ccode\u003eaxis1\u003c/code\u003e and \u003ccode\u003eaxis2\u003c/code\u003e parameters.\u003c/p\u003e\n"],["\u003cp\u003eThis function is useful for manipulating the structure of array images, such as changing the orientation of a 2D array.\u003c/p\u003e\n"]]],[],null,["# ee.Image.arrayTranspose\n\nTransposes two dimensions of each array pixel.\n\n\u003cbr /\u003e\n\n| Usage | Returns |\n|-----------------------------------------------|---------|\n| Image.arrayTranspose`(`*axis1* `, `*axis2*`)` | Image |\n\n| Argument | Type | Details |\n|---------------|---------------------|----------------------|\n| this: `input` | Image | Input image. |\n| `axis1` | Integer, default: 0 | First axis to swap. |\n| `axis2` | Integer, default: 1 | Second axis to swap. |\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 2D array image.\nvar arrayImg2D = ee.Image([0, 1, 2, 3, 4, 5]).toArray().arrayReshape(\n ee.Image([2, 3]).toArray(), 2);\nprint('2D 2x3 array image (pixel)', sampArrImg(arrayImg2D));\n// [[0, 1, 2],\n// [3, 4, 5]]\n\n// Swap 0-axis and 1-axis. Input is a 2x3 array, output will be 3x2.\nvar transposed = arrayImg2D.arrayTranspose();\nprint('Transposed (3x2) array image (pixel)', sampArrImg(transposed));\n// [[0, 3],\n// [1, 4],\n// [2, 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 2D array image.\narray_img_2d = ee.Image([0, 1, 2, 3, 4, 5]).toArray().arrayReshape(\n ee.Image([2, 3]).toArray(),\n 2\n)\nprint('2D 2x3 array image (pixel):', samp_arr_img(array_img_2d).getInfo())\n# [[0, 1, 2],\n# [3, 4, 5]]\n\n# Swap 0-axis and 1-axis. Input is a 2x3 array, output will be 3x2.\ntransposed = array_img_2d.arrayTranspose()\nprint('Transposed (3x2) array image (pixel):',\n samp_arr_img(transposed).getInfo())\n# [[0, 3],\n# [1, 4],\n# [2, 5]]\n```"]]