ArrayTools
ScanAlongDimension
accumulate the elements of an Array by a function
Calling Sequence
Parameters
Description
Examples
Compatibility
ScanAlongDimension(fcn,A,dim,opts)
fcn
-
function to accumulate along a dimension to a single value
A
Array
dim
(optional) dimension to add along
opts
(optional) one or more options
ScanAlongDimension(fcn,A,dim) accumulates with function fcn the elements in dimension dim of an N-dimensional Array to produce another Array with N dimensions.
When dim is not specified, the first non-singleton dimension is used for accumulation. If the dimension specified is a higher dimension than the number of dimensions in the input, the input itself 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].
ScanAlongDimensions usually returns a new Array with the same dimensions (but possibly different datatype) as A. Passing the option inplace or inplace=true causes A to be updated in-place. This option only applies to dense rectangular Arrays with no indexing functions, and causes the datatype option to be ignored.
This function is part of the ArrayTools package, so it can be used in the short form ScanAlongDimension(..) only after executing the command with(ArrayTools). However, it can always be accessed through the long form of the command by using ArrayTools[ScanAlongDimension](..).
with⁡ArrayTools:
M≔Matrix⁡a,b,c,d,e,f
M≔abcdef
ScanAlongDimension⁡`+`,M,1
abca+db+ec+f
ScanAlongDimension⁡`+`,M,2
aa+ba+b+cdd+ed+e+f
N≔Matrix⁡1,5,3,2,4,3
N≔153243
ScanAlongDimension⁡max,N,1
153253
ScanAlongDimension⁡max,N,2
155244
v≔Vectorrow⁡1,2,3,2,1
v≔12321
ScanAlongDimension⁡max,v
12333
ScanAlongDimension⁡a,b↦10⋅a+b,v
112123123212321
A≔Array⁡1..2,1..2,1..2,x,y,z↦a‖x‖y‖z
A1,A2
a111a112a121a122,a211a212a221a222
A1≔ScanAlongDimension⁡`+`,A,1
A11,A12
a111a112a121a122,a111+a211a112+a212a121+a221a122+a222
A2≔ScanAlongDimension⁡`+`,A,2
A21,A22
a111a112a111+a121a112+a122,a211a212a211+a221a212+a222
A3≔ScanAlongDimension⁡`+`,A,3
A31,A32
a111a111+a112a121a121+a122,a211a211+a212a221a221+a222
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
A≔14080304050
ScanAlongDimension⁡`+`,A,1
Error, (in ArrayTools:-ScanAlongDimension) unable to store '130' when datatype=integer[1]
ScanAlongDimension⁡`+`,A,1,datatype=integer2
140803180130
The ArrayTools[ScanAlongDimension] command was introduced in Maple 2021.
For more information on Maple 2021 changes, see Updates in Maple 2021.
See Also
ArrayTools[AddAlongDimension]
ArrayTools[MultiplyAlongDimension]
ArrayTools[ReduceAlongDimension]
Download Help Document