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.
Pads the array values in each pixel to be a fixed length. The pad value will be appended to each array to extend it to given length along each axis. All bands of the image must be array-valued and have the same dimensions.
Usage
Returns
Image.arrayPad(lengths, pad)
Image
Argument
Type
Details
this: image
Image
Array image to pad.
lengths
List
A list of desired lengths for each axis in the output arrays. Arrays are already as large or larger than the given length will be unchanged along that axis.
[[["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 2024-07-13 UTC."],[[["\u003cp\u003e\u003ccode\u003earrayPad\u003c/code\u003e extends the array values in each image pixel to a specified length using a provided pad value.\u003c/p\u003e\n"],["\u003cp\u003eIt accepts an array image, a list of desired lengths for each axis, and an optional pad value (defaulting to 0).\u003c/p\u003e\n"],["\u003cp\u003eIf an array is already at or beyond the desired length, it remains unchanged along that axis.\u003c/p\u003e\n"],["\u003cp\u003eAll bands in the image must be array-valued and share the same dimensions for the function to work correctly.\u003c/p\u003e\n"],["\u003cp\u003eThis function is useful for standardizing array lengths in images for further processing.\u003c/p\u003e\n"]]],[],null,["Pads the array values in each pixel to be a fixed length. The pad value will be appended to each array to extend it to given length along each axis. All bands of the image must be array-valued and have the same dimensions.\n\n\u003cbr /\u003e\n\n| Usage | Returns |\n|------------------------------------|---------|\n| Image.arrayPad`(lengths, `*pad*`)` | Image |\n\n| Argument | Type | Details |\n|---------------|--------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| this: `image` | Image | Array image to pad. |\n| `lengths` | List | A list of desired lengths for each axis in the output arrays. Arrays are already as large or larger than the given length will be unchanged along that axis. |\n| `pad` | Number, default: 0 | The value to pad with. |\n\nExamples\n\nCode 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// Pad 1D array to length of 5 with value 9.\nvar arrayImg1Dpad = arrayImg1D.arrayPad([5], 9);\nprint('1D array image padded', sampArrImg(arrayImg1Dpad));\n// [0, 1, 2, 9, 9]\n\n// Create a 2D array image.\nvar arrayImg2D = ee.Image([0, 1, 2, 3, 4, 5]).toArray()\n .arrayReshape(ee.Image([2, 3]).toArray(), 2);\nprint('2D 2x3 array image (pixel)', sampArrImg(arrayImg2D));\n// [[0, 1, 2],\n// [3, 4, 5]]\n\n// Pad 2D array to 0-axis length 3 and 1-axis length 5 with value 9.\nvar arrayImg2Dpad = arrayImg2D.arrayPad([3, 5], 9);\nprint('2D array image padded', sampArrImg(arrayImg2Dpad));\n// [[0, 1, 2, 9, 9],\n// [3, 4, 5, 9, 9],\n// [9, 9, 9, 9, 9]]\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\nColab (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# Pad 1D array to length of 5 with value 9.\narray_img_1d_pad = array_img_1d.arrayPad([5], 9)\nprint('1D array image padded:', samp_arr_img(array_img_1d_pad).getInfo())\n# [0, 1, 2, 9, 9]\n\n# Create a 2D array image.\narray_img_2d = ee.Image([0, 1, 2, 3, 4, 5]).toArray().arrayReshape(\n ee.Image([2, 3]).toArray(),\n 2\n)\nprint('2D 2x3 array image (pixel):', samp_arr_img(array_img_2d).getInfo())\n# [[0, 1, 2],\n# [3, 4, 5]]\n\n# Pad 2D array to 0-axis length 3 and 1-axis length 5 with value 9.\narray_img_2d_pad = array_img_2d.arrayPad([3, 5], 9)\nprint('2D array image padded:', samp_arr_img(array_img_2d_pad).getInfo())\n# [[0, 1, 2, 9, 9],\n# [3, 4, 5, 9, 9],\n# [9, 9, 9, 9, 9]]\n```"]]