Announcement: All noncommercial projects registered to use Earth Engine before April 15, 2025 must verify noncommercial eligibility to maintain Earth Engine access.
[[["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\u003earrayLength()\u003c/code\u003e returns the length of each pixel's array along a specified axis in an image.\u003c/p\u003e\n"],["\u003cp\u003eIt's used to get the size of array dimensions within images that have been converted to array format.\u003c/p\u003e\n"],["\u003cp\u003eThis function is crucial for understanding the structure and dimensions of array-based images in Earth Engine.\u003c/p\u003e\n"],["\u003cp\u003eBy providing the axis as an argument, you can get the length for specific dimensions (like rows or columns) of the array.\u003c/p\u003e\n"]]],[],null,["Returns the length of each pixel's array along the given axis.\n\n\u003cbr /\u003e\n\n| Usage | Returns |\n|---------------------------|---------|\n| Image.arrayLength`(axis)` | Image |\n\n| Argument | Type | Details |\n|---------------|---------|------------------------------------------|\n| this: `input` | Image | Input image. |\n| `axis` | Integer | The axis along which to take the length. |\n\nExamples\n\nCode Editor (JavaScript) \n\n```javascript\n// A function to print arrays 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// A 3-band image of constants.\nvar img = ee.Image([0, 1, 2]);\nprint('3-band image', img);\n\n// Convert the 3-band image to a 2D array image.\nvar arrayImg2D = img.toArray().toArray(1);\nprint('2D array image (pixel)', sampArrImg(arrayImg2D));\n// [[0],\n// [1],\n// [2]]\n\n// Get the number of dimensions in each pixel's array.\nvar arrayImg2Ddim = arrayImg2D.arrayDimensions();\nprint('N dimensions in array', sampArrImg(arrayImg2Ddim));\n// 2\n\n// Get the array length per dimension per pixel.\nvar arrayImg2DdimLen = arrayImg2D.arrayLengths();\nprint('Array length per dimension', sampArrImg(arrayImg2DdimLen));\n// [3, 1]\n\n// Get the array length for 0-axis (rows).\nvar arrayImg2Daxis0Len = arrayImg2D.arrayLength(0);\nprint('Array length 0-axis (rows)', sampArrImg(arrayImg2Daxis0Len));\n// 3\n\n// Get the array length for 1-axis (columns).\nvar arrayImg2Daxis1Len = arrayImg2D.arrayLength(1);\nprint('Array length 1-axis (columns)', sampArrImg(arrayImg2Daxis1Len));\n// 1\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 arrays 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# A 3-band image of constants.\nimg = ee.Image([0, 1, 2])\nprint('3-band image:', img.getInfo())\n\n# Convert the 3-band image to a 2D array image.\narray_img_2d = img.toArray().toArray(1)\nprint('2D array image (pixel):', samp_arr_img(array_img_2d).getInfo())\n# [[0],\n# [1],\n# [2]]\n\n# Get the number of dimensions in each pixel's array.\narray_img2d_dim = array_img_2d.arrayDimensions()\nprint('N dimensions in array:', samp_arr_img(array_img2d_dim).getInfo())\n# 2\n\n# Get the array length per dimension per pixel.\narray_img_2d_dim_len = array_img_2d.arrayLengths()\nprint(\n 'Array length per dimension:',\n samp_arr_img(array_img_2d_dim_len).getInfo()\n)\n# [3, 1]\n\n# Get the array length for 0-axis (rows).\narray_img2d_axis0_len = array_img_2d.arrayLength(0)\nprint(\n 'Array length 0-axis (rows):',\n samp_arr_img(array_img2d_axis0_len).getInfo()\n)\n# 3\n\n# Get the array length for 1-axis (columns).\narray_img_2d_axis1_len = array_img_2d.arrayLength(1)\nprint(\n 'Array length 1-axis (columns):',\n samp_arr_img(array_img_2d_axis1_len).getInfo()\n)\n# 1\n```"]]