ArrayTools
GeneralOuterProduct
compute a general outer product of two Arrays
Calling Sequence
Parameters
Description
Examples
Compatibility
GeneralOuterProduct(X,f,Y,opts)
X
-
Array, list, or expression
f
function to apply to each pair of values from X and Y
Y
opts
(optional) one or more options
GeneralOuterProduct(X,f,g,Y) accepts two Arrays, X and Y, with N and M dimensions respectively. The result is an Array of N+M dimensions.
For each combination of indices of X and indices of Y, the function f is applied to the elements from X and Y.
For example, when X and Y are vectors of integers from 1 to 10, and f is the multiplication function (`*`), GeneralOuterProduct produces a matrix representing a traditional multiplication table.
If X or Y is a list, it is treated as one-dimensional Array.
If either X or Y is not an Array or list, it is interpreted as an Array with zero dimensions (and the value X or Y).
By default, the datatype of the resulting Array is determined by SuggestedDatatype based on the two inputs. Depending on f, this may not be suitable. For example, if X and Y have datatype integer[1] and f is `*`, the computed values might 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 f are first evaluated to hardware floating-point using evalhf, as is the result returned by f. Furthermore, unless the datatype option was specified, the resulting Array has datatype float[8].
The subtype of the result depends on the subtypes of X and Y, as described by SuggestedSubtype. The option ':-subtype'=st', where st is a valid rtable subtype, overrides the default subtype.
The storage order of the result is based on the storage orders of X and Y, as described by SuggestedOrder. This can be overridden using the option :-order=ord, where ord is one of C_order or Fortran_order.
This function is part of the ArrayTools package, so it can be used in the short form GeneralOuterProduct(..) only after executing the command with(ArrayTools). However, it can always be accessed through the long form of the command by using ArrayTools[GeneralOuterProduct](..).
Produce a multiplication table of integers from 1 to 10.
with⁡ArrayTools:
V≔`$`⁡1..10:
GeneralOuterProduct⁡V,`*`,V
GeneralOuterProduct works with Arrays of arbitrary dimension. Generate a three-dimensional Array of the sum of all combinations of the roll of 3 dice:
R≔1,2,3,4,5,6:
2-D intermediate result
R2≔GeneralOuterProduct⁡R,`+`,R
R2≔
whattype⁡R2
Matrix
3-D final result
R3≔GeneralOuterProduct⁡R2,`+`,R
whattype⁡R3
Array
The possibilities when the last roll was 1.
R31
The possibilities when the last roll was 6.
R36
Count occurrences of each total from 1 to 18.
map2⁡numboccur,R3,`$`⁡1..18
0,0,1,3,6,10,15,21,25,27,27,25,21,15,10,6,3,1
The datatype option can be used if the default datatype would not be suitable for the result.
A≔Vectorrow⁡4,8,12,datatype=integer1
A≔
GeneralOuterProduct⁡A,`*`,A
Error, (in ArrayTools:-GeneralOuterProduct) unable to store '144' when datatype=integer[1]
GeneralOuterProduct⁡A,`*`,A,datatype=integer2
If the results of GeneralOuterProduct fall in the range 0..1, they can be visualized using ImageTools.
V≔Array⁡seq⁡i,i=0..1,numelems=101,datatype=float8:
V1..4
V−4..−1
img≔GeneralOuterProduct⁡V,max,V
img1..4,1..4
img−4..−1,−4..−1
with⁡ImageTools:
Embed⁡img
The ArrayTools[GeneralOuterProduct] command was introduced in Maple 2021.
For more information on Maple 2021 changes, see Updates in Maple 2021.
See Also
ArrayTools[GeneralInnerProduct]
ArrayTools[SuggestedDatatype]
ArrayTools[SuggestedOrder]
ArrayTools[SuggestedSubtype]
Download Help Document