|
Calling Sequence
|
|
GeneralOuterProduct(X,f,Y,opts)
|
|
Parameters
|
|
X
|
-
|
Array, list, or expression
|
f
|
-
|
function to apply to each pair of values from X and Y
|
Y
|
-
|
Array, list, or expression
|
opts
|
-
|
(optional) one or more options
|
|
|
|
|
Description
|
|
•
|
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](..).
|
|
|
Examples
|
|
Produce a multiplication table of integers from 1 to 10.
>
|
|
GeneralOuterProduct works with Arrays of arbitrary dimension. Generate a three-dimensional Array of the sum of all combinations of the roll of 3 dice:
>
|
|
2-D intermediate result
>
|
|
3-D final result
>
|
|
The possibilities when the last roll was 1.
The possibilities when the last roll was 6.
Count occurrences of each total from 1 to 18.
>
|
|
| (4.7) |
The datatype option can be used if the default datatype would not be suitable for the result.
>
|
|
>
|
|
>
|
|
If the results of GeneralOuterProduct fall in the range 0..1, they can be visualized using ImageTools.
>
|
|
>
|
|
|
|
Compatibility
|
|
•
|
The ArrayTools[GeneralOuterProduct] command was introduced in Maple 2021.
|
|
|
|