公告:凡是在
2025 年 4 月 15 日前註冊使用 Earth Engine 的非商業專案,都必須
驗證非商業用途資格,才能繼續存取 Earth Engine。
ee.Array.reduce
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
對陣列套用縮減器,方法是沿著每個指定軸將所有輸入值摺疊成單一輸出值,並由縮減器計算。
輸出內容的維度一律與輸入內容相同,個別軸的影響如下:
「axes」參數中指定的軸長度會縮減為 1 (套用縮減器)。
如果縮減器有多個輸入或多個輸出,系統會使用「fieldAxis」中指定的軸,提供縮減器的輸入內容,並儲存縮減器的輸出內容。
其他所有軸都不會受到影響 (系統會獨立執行縮減作業)。
用量 | 傳回 |
---|
Array.reduce(reducer, axes, fieldAxis) | 陣列 |
引數 | 類型 | 詳細資料 |
---|
這個:array | 陣列 | 陣列。 |
reducer | 縮減函式 | 要套用的縮減函式。每個輸出內容都必須是數字,不得為陣列或其他類型。 |
axes | 清單 | 要縮減的軸清單。在所有這些軸中,輸出內容的長度都會是 1。 |
fieldAxis | 整數,預設值為 null | 做為縮減器輸入和輸出欄位的軸。如果縮減器有多個輸入或多個輸出,才需要此欄位。在這種情況下,軸的長度必須等於縮減器輸入的數量,結果的長度則會等於縮減器輸出的數量。 |
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-07-26 (世界標準時間)。
[null,null,["上次更新時間:2025-07-26 (世界標準時間)。"],[[["\u003cp\u003e\u003ccode\u003eArray.reduce\u003c/code\u003e collapses input values along specified axes into single output values using a reducer function.\u003c/p\u003e\n"],["\u003cp\u003eThe output array retains the original input dimensionality, with specified axes reduced to length 1.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003efieldAxis\u003c/code\u003e is used when your reducer has multiple inputs or outputs, aligning with those fields.\u003c/p\u003e\n"],["\u003cp\u003eIndependent reductions are performed along all other axes not specified in the \u003ccode\u003eaxes\u003c/code\u003e parameter.\u003c/p\u003e\n"]]],[],null,["# ee.Array.reduce\n\nApply a reducer to an array by collapsing all the input values along each specified axis into a single output value computed by the reducer.\n\n\u003cbr /\u003e\n\nThe output always has the same dimensionality as the input, and the individual axes are affected as follows:\n\n- The axes specified in the 'axes' parameter have their length reduced to 1 (by applying the reducer).\n\n- If the reducer has multiple inputs or multiple outputs, the axis specified in 'fieldAxis' will be used to provide the reducer's inputs and store the reducer's outputs.\n\n- All other axes are unaffected (independent reductions are performed).\n\n| Usage | Returns |\n|----------------------------------------------|---------|\n| Array.reduce`(reducer, axes, `*fieldAxis*`)` | Array |\n\n| Argument | Type | Details |\n|---------------|------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| this: `array` | Array | The array. |\n| `reducer` | Reducer | The reducer to apply. Each of its outputs must be a number, not an array or other type. |\n| `axes` | List | The list of axes over which to reduce. The output will have a length of 1 in all these axes. |\n| `fieldAxis` | Integer, default: null | The axis to use as the reducer's input and output fields. Only required if the reducer has multiple inputs or multiple outputs, in which case the axis must have length equal to the number of reducer inputs, and in the result it will have length equal to the number of reducer outputs. |"]]