ee.Array.reduce
Zadbaj o dobrą organizację dzięki kolekcji
Zapisuj i kategoryzuj treści zgodnie ze swoimi preferencjami.
Zastosuj funkcję redukującą do tablicy, zwijając wszystkie wartości wejściowe wzdłuż każdego określonego osi w jedną wartość wyjściową obliczoną przez funkcję redukującą.
Dane wyjściowe mają zawsze taki sam wymiar jak dane wejściowe, a poszczególne osie są modyfikowane w ten sposób:
Długość osi określonych w parametrze „axes” jest zmniejszana do 1 (przez zastosowanie reduktora).
Jeśli funkcja redukująca ma wiele danych wejściowych lub wyjściowych, oś określona w parametrze „fieldAxis” będzie używana do dostarczania danych wejściowych funkcji redukującej i przechowywania jej danych wyjściowych.
Nie ma to wpływu na pozostałe osie (redukcje są przeprowadzane niezależnie).
Wykorzystanie | Zwroty |
---|
Array.reduce(reducer, axes, fieldAxis) | Tablica |
Argument | Typ | Szczegóły |
---|
to: array | Tablica | Tablica. |
reducer | Ograniczenie | Ograniczenie do zastosowania. Każde z jej wyjść musi być liczbą, a nie tablicą ani innym typem. |
axes | Lista | Lista osi, wzdłuż których ma nastąpić redukcja. Dane wyjściowe będą miały długość 1 na wszystkich osiach. |
fieldAxis | Liczba całkowita, domyślnie: null | Oś, która ma być używana jako pola wejściowe i wyjściowe funkcji redukującej. Wymagane tylko wtedy, gdy funkcja redukująca ma wiele danych wejściowych lub wyjściowych. W takim przypadku oś musi mieć długość równą liczbie danych wejściowych funkcji redukującej, a w wyniku będzie miała długość równą liczbie danych wyjściowych funkcji redukującej. |
O ile nie stwierdzono inaczej, treść tej strony jest objęta licencją Creative Commons – uznanie autorstwa 4.0, a fragmenty kodu są dostępne na licencji Apache 2.0. Szczegółowe informacje na ten temat zawierają zasady dotyczące witryny Google Developers. Java jest zastrzeżonym znakiem towarowym firmy Oracle i jej podmiotów stowarzyszonych.
Ostatnia aktualizacja: 2025-07-26 UTC.
[null,null,["Ostatnia aktualizacja: 2025-07-26 UTC."],[[["\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. |"]]