ee.Image.arrayRepeat
Restez organisé à l'aide des collections
Enregistrez et classez les contenus selon vos préférences.
Répète chaque pixel du tableau le long de l'axe donné. Chaque pixel de sortie aura la forme du pixel d'entrée, sauf la longueur le long de l'axe répété, qui sera multipliée par le nombre de copies.
Utilisation | Renvoie |
---|
Image.arrayRepeat(axis, copies) | Image |
Argument | Type | Détails |
---|
ceci : input | Image | Image des pixels du tableau à répéter. |
axis | Nombre entier | Axe le long duquel répéter le tableau de chaque pixel. |
copies | Image | Nombre de copies de chaque pixel. |
Exemples
Éditeur de code (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]]
Configuration de Python
Consultez la page
Environnement Python pour en savoir plus sur l'API Python et sur l'utilisation de geemap
pour le développement interactif.
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]]
Sauf indication contraire, le contenu de cette page est régi par une licence Creative Commons Attribution 4.0, et les échantillons de code sont régis par une licence Apache 2.0. Pour en savoir plus, consultez les Règles du site Google Developers. Java est une marque déposée d'Oracle et/ou de ses sociétés affiliées.
Dernière mise à jour le 2025/07/26 (UTC).
[null,null,["Dernière mise à jour le 2025/07/26 (UTC)."],[[["\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```"]]