公告:所有在
2025 年 4 月 15 日之前注册使用 Earth Engine 的非商业项目都必须
验证是否符合非商业性质的资格条件,才能继续使用 Earth Engine。
ee.Image.arrayTranspose
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
转置每个数组像素的两个维度。
用法 | 返回 |
---|
Image.arrayTranspose(axis1, axis2) | 图片 |
参数 | 类型 | 详细信息 |
---|
此:input | 图片 | 输入图片。 |
axis1 | 整数,默认值:0 | 要交换的第一个轴。 |
axis2 | 整数,默认值:1 | 要交换的第二个轴。 |
示例
代码编辑器 (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]]
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 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]]
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-26。
[null,null,["最后更新时间 (UTC):2025-07-26。"],[[["\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```"]]