公告:所有在
2025 年 4 月 15 日之前注册使用 Earth Engine 的非商业项目都必须
验证是否符合非商业性质的资格条件,才能继续使用 Earth Engine。
ee.Image.arrayRepeat
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
沿指定轴重复每个数组像素。每个输出像素的形状都将与输入像素的形状相同,但沿重复轴的长度除外,该长度将乘以副本数。
用法 | 返回 |
---|
Image.arrayRepeat(axis, copies) | 图片 |
参数 | 类型 | 详细信息 |
---|
此:input | 图片 | 要重复的数组像素的图片。 |
axis | 整数 | 重复每个像素数组所沿的轴。 |
copies | 图片 | 每个像素的副本数。 |
示例
代码编辑器 (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([0, 1, 2]).toArray();
print('1D array image (pixel)', sampArrImg(arrayImg1D));
// [0, 1, 2]
// Repeat a 1D array along the 0-axis 3 times.
var repeat1DAx0 = arrayImg1D.arrayRepeat(0, 3);
print('1D array repeated 3 times on 0-axis', sampArrImg(repeat1DAx0));
// [0, 1, 2, 0, 1, 2, 0, 1, 2]
// Repeat a 1D array along the 1-axis 3 times (expands the dimensions).
var repeat1DAx1 = arrayImg1D.arrayRepeat(1, 3);
print('1D array repeated 3 times on 1-axis', sampArrImg(repeat1DAx1));
// [[0, 0, 0],
// [1, 1, 1],
// [2, 2, 2]]
// Repeat a 2D array along the 0-axis 2 times.
var repeat2DAx0 = repeat1DAx1.arrayRepeat(0, 2);
print('2D array repeated 2 times on 0-axis', sampArrImg(repeat2DAx0));
// [[0, 0, 0],
// [1, 1, 1],
// [2, 2, 2],
// [0, 0, 0],
// [1, 1, 1],
// [2, 2, 2]]
// Repeat a 2D array along the 1-axis 2 times.
var repeat2DAx1 = repeat1DAx1.arrayRepeat(1, 2);
print('2D array repeated 2 times on 1-axis', sampArrImg(repeat2DAx1));
// [[0, 0, 0, 0, 0, 0],
// [1, 1, 1, 1, 1, 1],
// [2, 2, 2, 2, 2, 2]]
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([0, 1, 2]).toArray()
print('1D array image (pixel):', samp_arr_img(array_img_1d).getInfo())
# [0, 1, 2]
# Repeat a 1D array along the 0-axis 3 times.
repeat_1d_ax0 = array_img_1d.arrayRepeat(0, 3)
print(
'1D array repeated 3 times on 0-axis:',
samp_arr_img(repeat_1d_ax0).getInfo()
)
# [0, 1, 2, 0, 1, 2, 0, 1, 2]
# Repeat a 1D array along the 1-axis 3 times (expands the dimensions).
repeat_1d_ax1 = array_img_1d.arrayRepeat(1, 3)
print(
'1D array repeated 3 times on 1-axis:',
samp_arr_img(repeat_1d_ax1).getInfo()
)
# [[0, 0, 0],
# [1, 1, 1],
# [2, 2, 2]]
# Repeat a 2D array along the 0-axis 2 times.
repeat_2d_ax0 = repeat_1d_ax1.arrayRepeat(0, 2)
print(
'2D array repeated 2 times on 0-axis:',
samp_arr_img(repeat_2d_ax0).getInfo()
)
# [[0, 0, 0],
# [1, 1, 1],
# [2, 2, 2],
# [0, 0, 0],
# [1, 1, 1],
# [2, 2, 2]]
# Repeat a 2D array along the 1-axis 2 times.
repeat_2d_ax1 = repeat_1d_ax1.arrayRepeat(1, 2)
print(
'2D array repeated 2 times on 1-axis:',
samp_arr_img(repeat_2d_ax1).getInfo()
)
# [[0, 0, 0, 0, 0, 0],
# [1, 1, 1, 1, 1, 1],
# [2, 2, 2, 2, 2, 2]]
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-26。
[null,null,["最后更新时间 (UTC):2025-07-26。"],[[["\u003cp\u003e\u003ccode\u003eImage.arrayRepeat()\u003c/code\u003e duplicates each pixel's array along a specified axis, creating a new image.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eaxis\u003c/code\u003e parameter determines the dimension along which the repetition occurs (0 or 1 for 1D/2D arrays).\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003ecopies\u003c/code\u003e parameter specifies the number of times to repeat the array elements along the given axis.\u003c/p\u003e\n"],["\u003cp\u003eRepeating along an existing axis extends the array in that dimension, while repeating along a new axis adds a new dimension to the array.\u003c/p\u003e\n"],["\u003cp\u003eThis function is useful for expanding array images or creating patterned data within an image's array structure.\u003c/p\u003e\n"]]],[],null,["# ee.Image.arrayRepeat\n\nRepeats each array pixel along the given axis. Each output pixel will have the shape of the input pixel, except length along the repeated axis, which will be multiplied by the number of copies.\n\n\u003cbr /\u003e\n\n| Usage | Returns |\n|-----------------------------------|---------|\n| Image.arrayRepeat`(axis, copies)` | Image |\n\n| Argument | Type | Details |\n|---------------|---------|------------------------------------------------|\n| this: `input` | Image | Image of array pixels to be repeated. |\n| `axis` | Integer | Axis along which to repeat each pixel's array. |\n| `copies` | Image | Number of copies of each pixel. |\n\nExamples\n--------\n\n### Code Editor (JavaScript)\n\n```javascript\n// A function to print the array 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.\nvar arrayImg1D = ee.Image([0, 1, 2]).toArray();\nprint('1D array image (pixel)', sampArrImg(arrayImg1D));\n// [0, 1, 2]\n\n// Repeat a 1D array along the 0-axis 3 times.\nvar repeat1DAx0 = arrayImg1D.arrayRepeat(0, 3);\nprint('1D array repeated 3 times on 0-axis', sampArrImg(repeat1DAx0));\n// [0, 1, 2, 0, 1, 2, 0, 1, 2]\n\n// Repeat a 1D array along the 1-axis 3 times (expands the dimensions).\nvar repeat1DAx1 = arrayImg1D.arrayRepeat(1, 3);\nprint('1D array repeated 3 times on 1-axis', sampArrImg(repeat1DAx1));\n// [[0, 0, 0],\n// [1, 1, 1],\n// [2, 2, 2]]\n\n// Repeat a 2D array along the 0-axis 2 times.\nvar repeat2DAx0 = repeat1DAx1.arrayRepeat(0, 2);\nprint('2D array repeated 2 times on 0-axis', sampArrImg(repeat2DAx0));\n// [[0, 0, 0],\n// [1, 1, 1],\n// [2, 2, 2],\n// [0, 0, 0],\n// [1, 1, 1],\n// [2, 2, 2]]\n\n// Repeat a 2D array along the 1-axis 2 times.\nvar repeat2DAx1 = repeat1DAx1.arrayRepeat(1, 2);\nprint('2D array repeated 2 times on 1-axis', sampArrImg(repeat2DAx1));\n// [[0, 0, 0, 0, 0, 0],\n// [1, 1, 1, 1, 1, 1],\n// [2, 2, 2, 2, 2, 2]]\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 the array 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.\narray_img_1d = ee.Image([0, 1, 2]).toArray()\nprint('1D array image (pixel):', samp_arr_img(array_img_1d).getInfo())\n# [0, 1, 2]\n\n# Repeat a 1D array along the 0-axis 3 times.\nrepeat_1d_ax0 = array_img_1d.arrayRepeat(0, 3)\nprint(\n '1D array repeated 3 times on 0-axis:',\n samp_arr_img(repeat_1d_ax0).getInfo()\n)\n# [0, 1, 2, 0, 1, 2, 0, 1, 2]\n\n# Repeat a 1D array along the 1-axis 3 times (expands the dimensions).\nrepeat_1d_ax1 = array_img_1d.arrayRepeat(1, 3)\nprint(\n '1D array repeated 3 times on 1-axis:',\n samp_arr_img(repeat_1d_ax1).getInfo()\n)\n# [[0, 0, 0],\n# [1, 1, 1],\n# [2, 2, 2]]\n\n# Repeat a 2D array along the 0-axis 2 times.\nrepeat_2d_ax0 = repeat_1d_ax1.arrayRepeat(0, 2)\nprint(\n '2D array repeated 2 times on 0-axis:',\n samp_arr_img(repeat_2d_ax0).getInfo()\n)\n# [[0, 0, 0],\n# [1, 1, 1],\n# [2, 2, 2],\n# [0, 0, 0],\n# [1, 1, 1],\n# [2, 2, 2]]\n\n# Repeat a 2D array along the 1-axis 2 times.\nrepeat_2d_ax1 = repeat_1d_ax1.arrayRepeat(1, 2)\nprint(\n '2D array repeated 2 times on 1-axis:',\n samp_arr_img(repeat_2d_ax1).getInfo()\n)\n# [[0, 0, 0, 0, 0, 0],\n# [1, 1, 1, 1, 1, 1],\n# [2, 2, 2, 2, 2, 2]]\n```"]]