Close
Close window
ReduceAlongDimension - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Mozilla Firefox.
Maplesoft logo
Maplesoft logo

Online Help

All Products Maple MapleSim


[フレーム] [フレーム]

ArrayTools

ReduceAlongDimension

reduce the elements of an Array by a function

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

Aa111a121a211a221slice of 2 × 2 × 2 Array

(7)
>

A1,A2

a111a112a121a122,a211a212a221a222

(8)
>

ReduceAlongDimension`+`,A,1

a111+a211a112+a212a121+a221a122+a222

(9)
>

ReduceAlongDimension`+`,A,2

a111+a121a112+a122a211+a221a212+a222

(10)
>

ReduceAlongDimension`+`,A,3

a111+a112a121+a122a211+a212a221+a222

(11)

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

(12)
>

ReduceAlongDimension`+`,A,1

>

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

3180130

(13)

Compatibility

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

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


Download Help Document

AltStyle によって変換されたページ (->オリジナル) /