The dot product between arrays with different dimensions is computed by taking the inner product on the last dimensions of the two arrays.

x %dot% y

Arguments

x

numeric or character array.

y

numeric or character array.

Value

array.

Details

The dot product between two arrays A and B is computed as: $$C_{i_1\dots i_m} = \sum_{j_1\dots j_n} A_{i_1\dots i_mj_1\dots j_n}B_{j_1\dots j_n}$$

References

Guidotti, E. (2020). "calculus: High dimensional numerical and symbolic calculus in R". https://arxiv.org/abs/2101.00086

See also

Other basic arithmetic: %diff%(), %div%(), %inner%(), %kronecker%(), %outer%(), %prod%(), %sum%()

Examples

### inner product x <- array(1:12, dim = c(3,4)) x %dot% x
#> [1] 650
### dot product x <- array(1:24, dim = c(3,2,4)) y <- array(letters[1:8], dim = c(2,4)) x %dot% y
#> [1] "1 * (a) + 4 * (b) + 7 * (c) + 10 * (d) + 13 * (e) + 16 * (f) + 19 * (g) + 22 * (h)" #> [2] "2 * (a) + 5 * (b) + 8 * (c) + 11 * (d) + 14 * (e) + 17 * (f) + 20 * (g) + 23 * (h)" #> [3] "3 * (a) + 6 * (b) + 9 * (c) + 12 * (d) + 15 * (e) + 18 * (f) + 21 * (g) + 24 * (h)"