Annuncio: tutti i progetti non commerciali registrati per l'utilizzo di Earth Engine prima del
15 aprile 2025 devono
verificare l'idoneità non commerciale per mantenere l'accesso a Earth Engine.
ee.Image.arrayRepeat
Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
Ripete ogni pixel dell'array lungo l'asse specificato. Ogni pixel di output avrà la forma del pixel di input, ad eccezione della lunghezza lungo l'asse ripetuto, che verrà moltiplicata per il numero di copie.
Utilizzo | Resi |
---|
Image.arrayRepeat(axis, copies) | Immagine |
Argomento | Tipo | Dettagli |
---|
questo: input | Immagine | Immagine dei pixel dell'array da ripetere. |
axis | Numero intero | Asse lungo il quale ripetere l'array di ciascun pixel. |
copies | Immagine | Numero di copie di ogni pixel. |
Esempi
Editor di codice (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]]
Configurazione di Python
Consulta la pagina
Ambiente Python per informazioni sull'API Python e sull'utilizzo di
geemap
per lo sviluppo interattivo.
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]]
Salvo quando diversamente specificato, i contenuti di questa pagina sono concessi in base alla licenza Creative Commons Attribution 4.0, mentre gli esempi di codice sono concessi in base alla licenza Apache 2.0. Per ulteriori dettagli, consulta le norme del sito di Google Developers. Java è un marchio registrato di Oracle e/o delle sue consociate.
Ultimo aggiornamento 2025-07-26 UTC.
[null,null,["Ultimo aggiornamento 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```"]]