Announcement: All noncommercial projects registered to use Earth Engine before April 15, 2025 must verify noncommercial eligibility to maintain Earth Engine access.
Stay organized with collections
Save and categorize content based on your preferences.
Repeats 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.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2023-10-06 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```"]]