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

Online Help

All Products    Maple    MapleSim


ArrayTools

  

GeneralOuterProduct

  

compute a general outer product of two Arrays

 

Calling Sequence

Parameters

Description

Examples

Compatibility

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.

withArrayTools:

V`$`1..10:

GeneralOuterProductV,`*`,V

(4.1)

GeneralOuterProduct works with Arrays of arbitrary dimension. Generate a three-dimensional Array of the sum of all combinations of the roll of 3 dice:

R1,2,3,4,5,6:

2-D intermediate result

R2GeneralOuterProductR,`+`,R

R2

(4.2)

whattypeR2

Matrix

(4.3)

3-D final result

R3GeneralOuterProductR2,`+`,R

whattypeR3

Array

(4.4)

The possibilities when the last roll was 1.

R31

(4.5)

The possibilities when the last roll was 6.

R36

(4.6)

Count occurrences of each total from 1 to 18.

map2numboccur,R3,`$`1..18

0,0,1,3,6,10,15,21,25,27,27,25,21,15,10,6,3,1

(4.7)

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

AVectorrow4,8,12,datatype=integer1

A

(4.8)

GeneralOuterProductA,`*`,A

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

GeneralOuterProductA,`*`,A,datatype=integer2

(4.9)

If the results of GeneralOuterProduct fall in the range 0..1, they can be visualized using ImageTools.

VArrayseqi,i=0..1,numelems=101,datatype=float8:

V1..4

(4.10)

V4..1

imgGeneralOuterProductV,max,V

img1..4,1..4

(4.11)

img4..1,4..1

withImageTools:

Embedimg

Compatibility

• 

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

• 

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

See Also

ArrayTools

ArrayTools[GeneralInnerProduct]

ArrayTools[SuggestedDatatype]

ArrayTools[SuggestedOrder]

ArrayTools[SuggestedSubtype]