ReduceAlongDimension - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

Online Help

All Products    Maple    MapleSim


ArrayTools

  

ReduceAlongDimension

  

reduce the elements of an Array by a function

 

Calling Sequence

Parameters

Description

Examples

Compatibility

Calling Sequence

ReduceAlongDimension(fcn,A,dim,opts)

Parameters

fcn

-

function to reduce along a dimension to a single value

A

-

Array

dim

-

(optional) dimension to add along

opts

-

(optional) one or more options

Description

• 

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[1], 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[8].

• 

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](..).

Examples

withArrayTools:

Collapse a Matrix into a Vector of row or column totals.

MMatrixa,b,c,d,e,f

Mabcdef

(1)

ReduceAlongDimension`+`,M,1

a+db+ec+f

(2)

ReduceAlongDimension`+`,M,2

a+b+cd+e+f

(3)

Find the maximum per column or row of a Matrix.

NMatrix3,1,4,1,5,9,2,6,5

N314159265

(4)

ReduceAlongDimensionmax,N,1

369

(5)

ReduceAlongDimensionmax,N,2

496

(6)

Compute sums along each dimension of a three-dimensional Array.

AArray1..2,1..2,1..2,x,y,zaxyz

A1,A2

a111a112a121a122,a211a212a221a222

(7)

ReduceAlongDimension`+`,A,1

a111+a211a112+a212a121+a221a122+a222

(8)

ReduceAlongDimension`+`,A,2

a111+a121a112+a122a211+a221a212+a222

(9)

ReduceAlongDimension`+`,A,3

a111+a112a121+a122a211+a212a221+a222

(10)

The datatype option can be used if the input datatype would not be suitable for the result.

AArray1,40,80,30,40,50,datatype=integer1

A14080304050

(11)

ReduceAlongDimension`+`,A,1

Error, (in ArrayTools:-ReduceAlongDimension) unable to store '130' when datatype=integer[1]

ReduceAlongDimension`+`,A,1,datatype=integer2

3180130

(12)

Compatibility

• 

The ArrayTools[ReduceAlongDimension] command was introduced in Maple 2021.

• 

For more information on Maple 2021 changes, see Updates in Maple 2021.

See Also

ArrayTools

ArrayTools[AddAlongDimension]

ArrayTools[MultiplyAlongDimension]

ArrayTools[ScanAlongDimension]