reducedim(f, A, dims[, initial])

Reduce 2-argument function f along dimensions of A. dims is a vector specifying the dimensions to reduce, and initial is the initial value to use in the reductions. For +, *, max and min the initial argument is optional.

The associativity of the reduction is implementation-dependent; if you need a particular associativity, e.g. left-to-right, you should write your own loop. See documentation for reduce.


In the Julia programming language, the function reducedim(f, A, dims[, initial]) is used to reduce a multi-dimensional array along specified dimensions using a provided function f. The dims argument specifies the dimensions to reduce, and the optional initial argument is used as the initial value in the reductions for certain functions (+, *, max, and min).

julia> A = [1 2 3; 4 5 6; 7 8 9]
3×3 Array{Int64,2}:
 1  2  3
 4  5  6
 7  8  9

julia> reducedim(+, A, 1)
1×3 Array{Int64,2}:
 12  15  18

julia> reducedim(min, A, 2)
3×1 Array{Int64,2}:

In the above example, the reducedim function is used to reduce the array A along the specified dimensions. The provided function f (in this case, + and min) is applied to the elements along the specified dimensions, resulting in a reduced array.

Note: The associativity of the reduction is implementation-dependent. If a specific associativity is required (e.g., left-to-right), it is recommended to write a custom loop using the reduce function.

Please refer to the documentation for reduce for more information on customizing reductions.

See Also

User Contributed Notes

Add a Note

The format of note supported is markdown, use triple backtick to start and end a code block.

*Required Field

Checking you are not a robot: