reduce the elements of an Array by a function
function to reduce along a dimension to a single value
(optional) dimension to add along
(optional) one or more options
ReduceAlongDimension(fcn,A,dim) reduces with function fcn the elements in dimension dim of an N-dimensional Array to produce an Array with (N-1) dimensions.
When dim is not specified, the first non-singleton dimension is used for reduction. If the dimension specified is a higher dimension than the number of dimensions in the input, the input itself is returned.
If ReduceAlongDimension is applied to a Vector, a scalar is returned. If applied to a Matrix, a Vector is returned.
By default, the datatype of the result Array is the same as that of input Array A. Depending on fcn, this may not be suitable. For example, if A has datatype integer, and fcn adds up values, the result may be too large to store in that datatype.
The option ':-datatype'=dt, where dt is a valid Array datatype, can be used to override the default datatype for the result.
If option evalhf or evalhf=true is passed, the arguments passed to each call to fcn are first evaluated to hardware floating-point using evalhf, as is the result returned by fcn. Furthermore, unless the datatype option was specified, the result Array will have datatype float.
This function is part of the ArrayTools package, so it can be used in the short form ReduceAlongDimension(..) only after executing the command with(ArrayTools). However, it can always be accessed through the long form of the command by using ArrayTools[ReduceAlongDimension](..).
Collapse a Matrix into a Vector of row or column totals.
M ≔ Matrix⁡a,b,c,d,e,f
Find the maximum per column or row of a Matrix.
N ≔ Matrix⁡3,1,4,1,5,9,2,6,5
Compute sums along each dimension of a three-dimensional Array.
A ≔ Array⁡1..2,1..2,1..2,x,y,z→a||x||y||z
The datatype option can be used if the input datatype would not be suitable for the result.
A ≔ Array⁡1,40,80,30,40,50,datatype=integer1
Error, (in ArrayTools:-ReduceAlongDimension) unable to store '130' when datatype=integer
The ArrayTools[ReduceAlongDimension] command was introduced in Maple 2021.
For more information on Maple 2021 changes, see Updates in Maple 2021.
Download Help Document