Function Repository Resource:

# AssociationOuter

Compute the generalized outer product of lists and get an association keyed by arguments

Contributed by: Richard Hennigan (Wolfram Research)
 ResourceFunction["AssociationOuter"][f,list1,list2,…] gives the generalized outer product of the listi as a nested association, forming all possible combinations of the lowest-level elements in each of them as keys, and feeding them as arguments to f for values. ResourceFunction["AssociationOuter"][f,list1,list2,…,n] treats as separate elements only sublists at level n in the listi. ResourceFunction["AssociationOuter"][f,list1,list2,…,n1,n2,…] treats as separate elements only sublists at level ni in the corresponding listi.

## Details

ResourceFunction["AssociationOuter"][f,list1,list2,] computes all the same f[] as Outer[f,list1,list2,]
ResourceFunction["AssociationOuter"][Times,list1,list2] gives an outer product.
Unlike Outer, the heads of all listi must be List.
The listi need not necessarily be cuboidal arrays.
The specifications ni of levels must be positive integers, or Infinity.
If only a single level specification is given, it is assumed to apply to all the listi. If there are several ni, but fewer than the number of listi, the lowest-level elements in the remaining listi will be used.
ResourceFunction["AssociationOuter"] can be used on SparseArray objects, returning a SparseArray object when possible.
ResourceFunction["AssociationOuter"][f,list] is effectively equivalent to AssociationMap[f,list].

## Examples

### Basic Examples (2)

Compute an outer product:

 In:= Out= Compare to Outer:

 In:= Out= Outer product of vectors:

 In:= Out= Outer product of matrices:

 In:= Out= ### Scope (4)

The keys are nested so that values can be retrieved in argument order:

 In:= Out= In:= Out= In:= Out= Treat nested lists as rank-1 vectors of sublists:

 In:= Out= Arrays can be ragged:

 In:= Out= Outer product of SparseArray objects:

 In:= In:= Out= ### Applications (4)

Word combinations:

 In:= Out= Function combinations:

 In:= Out= In:= Out= Complete bipartite graph:

 In:= Out= Generate all possible binary trees with nodes from f and leaves from e to depth n:

 In:= In:= Out= ### Properties & Relations (6)

If each of the listi are duplicate-free, dimensions of the result are a concatenation of the dimensions of the inputs:

 In:= Out= In:= Out= If there are duplicates, the dimensions will correspond to the number of unique elements in each listi:

 In:= Out= In:= Out= Compare to Outer, which is unaffected by duplicates:

 In:= Out= In:= Out= Use Map and Values to convert the result into the format given by Outer:

 In:= Out= In:= Out= In:= Out= AssociationKeyFlatten can be used to convert the result into a flat association:

 In:= Out= In:= Out= Restore the nested structure with AssociationKeyDeflatten:

 In:= Out= Distribute forms the same combinations of all elements, but in a flat structure:

 In:= Out= In:= Out= Use AssociationKeyFlatten and Values to get the same result:

 In:= Out= AssociationOuter relates to Outer much like AssociationMap relates to Map:

 In:= Out= In:= Out= In:= Out= In:= Out= ### Possible Issues (3)

Unlike Outer, the head must be List:

 In:=  Out= In:= Out= Unlike Outer, at least two arguments are required:

 In:=  Out= In:= Out= Values are nested by arguments in the order they were given to f, even if f is Orderless:

 In:= Out= In:= Out= In:= Out= ## Version History

• 1.0.0 – 20 December 2021