公告:凡是在
2025 年 4 月 15 日前註冊使用 Earth Engine 的非商業專案,都必須
驗證非商業用途資格,才能繼續存取 Earth Engine。
ee.Image.arrayDimensions
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
傳回每個陣列頻帶的維度數量,如果是純量圖片頻帶,則傳回 0。
用量 | 傳回 |
---|
Image.arrayDimensions() | 圖片 |
範例
程式碼編輯器 (JavaScript)
// A function to print arrays 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');
}
// A 3-band image of constants.
var img = ee.Image([0, 1, 2]);
print('3-band image', img);
// Convert the 3-band image to a 2D array image.
var arrayImg2D = img.toArray().toArray(1);
print('2D array image (pixel)', sampArrImg(arrayImg2D));
// [[0],
// [1],
// [2]]
// Get the number of dimensions in each pixel's array.
var arrayImg2Ddim = arrayImg2D.arrayDimensions();
print('N dimensions in array', sampArrImg(arrayImg2Ddim));
// 2
// Get the array length per dimension per pixel.
var arrayImg2DdimLen = arrayImg2D.arrayLengths();
print('Array length per dimension', sampArrImg(arrayImg2DdimLen));
// [3, 1]
// Get the array length for 0-axis (rows).
var arrayImg2Daxis0Len = arrayImg2D.arrayLength(0);
print('Array length 0-axis (rows)', sampArrImg(arrayImg2Daxis0Len));
// 3
// Get the array length for 1-axis (columns).
var arrayImg2Daxis1Len = arrayImg2D.arrayLength(1);
print('Array length 1-axis (columns)', sampArrImg(arrayImg2Daxis1Len));
// 1
Python 設定
請參閱
Python 環境頁面,瞭解 Python API 和如何使用 geemap
進行互動式開發。
import ee
import geemap.core as geemap
Colab (Python)
# A function to print arrays 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')
# A 3-band image of constants.
img = ee.Image([0, 1, 2])
print('3-band image:', img.getInfo())
# Convert the 3-band image to a 2D array image.
array_img_2d = img.toArray().toArray(1)
print('2D array image (pixel):', samp_arr_img(array_img_2d).getInfo())
# [[0],
# [1],
# [2]]
# Get the number of dimensions in each pixel's array.
array_img_2d_dim = array_img_2d.arrayDimensions()
print('N dimensions in array:', samp_arr_img(array_img_2d_dim).getInfo())
# 2
# Get the array length per dimension per pixel.
array_img_2d_dim_len = array_img_2d.arrayLengths()
print(
'Array length per dimension:',
samp_arr_img(array_img_2d_dim_len).getInfo()
)
# [3, 1]
# Get the array length for 0-axis (rows).
array_img_2d_axis0_len = array_img_2d.arrayLength(0)
print(
'Array length 0-axis (rows):',
samp_arr_img(array_img_2d_axis0_len).getInfo()
)
# 3
# Get the array length for 1-axis (columns).
array_img_2d_axis1_len = array_img_2d.arrayLength(1)
print(
'Array length 1-axis (columns):',
samp_arr_img(array_img_2d_axis1_len).getInfo()
)
# 1
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-07-26 (世界標準時間)。
[null,null,["上次更新時間:2025-07-26 (世界標準時間)。"],[[["\u003cp\u003eReturns the number of dimensions in each array band of an image.\u003c/p\u003e\n"],["\u003cp\u003eOutputs 0 for scalar image bands, indicating no dimensions.\u003c/p\u003e\n"],["\u003cp\u003eAccepts an input image and applies the operation on a per-pixel basis.\u003c/p\u003e\n"],["\u003cp\u003eProvides information about the structure of array-based images in Earth Engine.\u003c/p\u003e\n"]]],["The `arrayDimensions()` method determines the number of dimensions in each array band of an image, returning 0 for scalar bands. The examples demonstrate creating a 3-band image, converting it to a 2D array image, and then using `arrayDimensions()` to find the number of dimensions which was 2. Additionaly, it uses the `arrayLengths()` to get the lengths per dimension. The code is presented in both JavaScript and Python, showcasing consistent functionality.\n"],null,["# ee.Image.arrayDimensions\n\nReturns the number of dimensions in each array band, and 0 for scalar image bands.\n\n\u003cbr /\u003e\n\n| Usage | Returns |\n|---------------------------|---------|\n| Image.arrayDimensions`()` | Image |\n\n| Argument | Type | Details |\n|---------------|-------|--------------|\n| this: `input` | Image | Input image. |\n\nExamples\n--------\n\n### Code 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\n### Colab (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_img_2d_dim = array_img_2d.arrayDimensions()\nprint('N dimensions in array:', samp_arr_img(array_img_2d_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_img_2d_axis0_len = array_img_2d.arrayLength(0)\nprint(\n 'Array length 0-axis (rows):',\n samp_arr_img(array_img_2d_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```"]]