ee.Array.reduce
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
ใช้ตัวลดกับอาร์เรย์โดยการยุบค่าอินพุตทั้งหมดตามแต่ละแกนที่ระบุเป็นค่าเอาต์พุตเดียวที่คำนวณโดยตัวลด
เอาต์พุตจะมีมิติข้อมูลเหมือนกับอินพุตเสมอ และแกนแต่ละแกนจะได้รับผลกระทบดังนี้
แกนที่ระบุในพารามิเตอร์ "axes" จะมีความยาวลดลงเหลือ 1 (โดยใช้ตัวลด)
หากตัวลดมีอินพุตหรือเอาต์พุตหลายรายการ ระบบจะใช้แกนที่ระบุใน "fieldAxis" เพื่อจัดเตรียมอินพุตของตัวลดและจัดเก็บเอาต์พุตของตัวลด
แกนอื่นๆ ทั้งหมดจะไม่ได้รับผลกระทบ (จะมีการลดอิสระ)
การใช้งาน | การคืนสินค้า |
---|
Array.reduce(reducer, axes, fieldAxis) | อาร์เรย์ |
อาร์กิวเมนต์ | ประเภท | รายละเอียด |
---|
ดังนี้ array | อาร์เรย์ | อาร์เรย์ |
reducer | ตัวลดตำแหน่ง | ตัวลดที่จะใช้ เอาต์พุตแต่ละรายการต้องเป็นตัวเลข ไม่ใช่อาร์เรย์หรือประเภทอื่นๆ |
axes | รายการ | รายการแกนที่จะลด เอาต์พุตจะมีขนาด 1 ในแกนทั้งหมดนี้ |
fieldAxis | จำนวนเต็ม ค่าเริ่มต้น: null | แกนที่จะใช้เป็นฟิลด์อินพุตและเอาต์พุตของตัวลด ต้องระบุในกรณีที่ตัวลดมีอินพุตหรือเอาต์พุตหลายรายการ ซึ่งในกรณีนี้ แกนต้องมีความยาวเท่ากับจำนวนอินพุตของตัวลด และในผลลัพธ์แกนจะมีความยาวเท่ากับจำนวนเอาต์พุตของตัวลด |
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-07-26 UTC
[null,null,["อัปเดตล่าสุด 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. |"]]