公告:所有在
2025 年 4 月 15 日之前注册使用 Earth Engine 的非商业项目都必须
验证是否符合非商业性质的资格条件,才能继续使用 Earth Engine。
ee.Image.arrayProject
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
通过指定要保留的轴,将每个像素中的数组投影到较低维度的空间。被舍弃的轴的长度不得超过 1。
用法 | 返回 |
---|
Image.arrayProject(axes) | 图片 |
参数 | 类型 | 详细信息 |
---|
此:input | 图片 | 输入图片。 |
axes | 列表 | 要保留的轴。其他轴将被舍弃,且长度不得超过 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 with the 0-axis having length 6 and the 1-axis
// having length 1.
var arrayImg2D = ee.Image([0, 1, 2, 3, 4, 5]).toArray().toArray(1);
print('2D array image (pixel)', sampArrImg(arrayImg2D));
// [[0],
// [1],
// [2],
// [3],
// [4],
// [5]]
// Project the 2D array to a 1D array, retain the 0-axis (concatenate elements
// from the 1-axis into the 0-axis).
var arrayImg2Dto1D = arrayImg2D.arrayProject([0]);
print('2D array image (pixel)', sampArrImg(arrayImg2Dto1D));
// [0, 1, 2, 3, 4, 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 with the 0-axis having length 6 and the 1-axis
# having length 1.
array_img_2d = ee.Image([0, 1, 2, 3, 4, 5]).toArray().toArray(1)
print('2D array image (pixel):', samp_arr_img(array_img_2d).getInfo())
# [[0],
# [1],
# [2],
# [3],
# [4],
# [5]]
# Project the 2D array to a 1D array, retain the 0-axis (concatenate elements
# from the 1-axis into the 0-axis).
array_img_2d_to_1d = array_img_2d.arrayProject([0])
print('2D array image (pixel):', samp_arr_img(array_img_2d_to_1d).getInfo())
# [0, 1, 2, 3, 4, 5]
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-26。
[null,null,["最后更新时间 (UTC):2025-07-26。"],[[["\u003cp\u003e\u003ccode\u003earrayProject\u003c/code\u003e reduces the dimensionality of an array image by projecting it onto specified axes.\u003c/p\u003e\n"],["\u003cp\u003eDropped axes must have a maximum length of 1, meaning they can't contain more than one element along that dimension.\u003c/p\u003e\n"],["\u003cp\u003eThis operation effectively reshapes the array within each pixel of the image, retaining data from the specified \u003ccode\u003eaxes\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eIt's useful for operations like concatenating elements from different axes or reducing the complexity of an array image.\u003c/p\u003e\n"]]],[],null,["# ee.Image.arrayProject\n\nProjects the array in each pixel to a lower dimensional space by specifying the axes to retain. Dropped axes must be at most length 1.\n\n\u003cbr /\u003e\n\n| Usage | Returns |\n|----------------------------|---------|\n| Image.arrayProject`(axes)` | Image |\n\n| Argument | Type | Details |\n|---------------|-------|--------------------------------------------------------------------------------|\n| this: `input` | Image | Input image. |\n| `axes` | List | The axes to retain. Other axes will be discarded and must be at most length 1. |\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 with the 0-axis having length 6 and the 1-axis\n// having length 1.\nvar arrayImg2D = ee.Image([0, 1, 2, 3, 4, 5]).toArray().toArray(1);\nprint('2D array image (pixel)', sampArrImg(arrayImg2D));\n// [[0],\n// [1],\n// [2],\n// [3],\n// [4],\n// [5]]\n\n// Project the 2D array to a 1D array, retain the 0-axis (concatenate elements\n// from the 1-axis into the 0-axis).\nvar arrayImg2Dto1D = arrayImg2D.arrayProject([0]);\nprint('2D array image (pixel)', sampArrImg(arrayImg2Dto1D));\n// [0, 1, 2, 3, 4, 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 with the 0-axis having length 6 and the 1-axis\n# having length 1.\narray_img_2d = ee.Image([0, 1, 2, 3, 4, 5]).toArray().toArray(1)\nprint('2D array image (pixel):', samp_arr_img(array_img_2d).getInfo())\n# [[0],\n# [1],\n# [2],\n# [3],\n# [4],\n# [5]]\n\n# Project the 2D array to a 1D array, retain the 0-axis (concatenate elements\n# from the 1-axis into the 0-axis).\narray_img_2d_to_1d = array_img_2d.arrayProject([0])\nprint('2D array image (pixel):', samp_arr_img(array_img_2d_to_1d).getInfo())\n# [0, 1, 2, 3, 4, 5]\n```"]]