ArrayDot[a,b,k]
computes the product of arrays a and b obtained by summing up products of terms over the last k dimensions of a and the first k dimensions of b.
ArrayDot[a,b,{{s1,t1},{s2,t2},…}]
computes the product of arrays a and b obtained by summing up products of terms over the pairs {si,ti} of dimensions.
ArrayDot
ArrayDot[a,b,k]
computes the product of arrays a and b obtained by summing up products of terms over the last k dimensions of a and the first k dimensions of b.
ArrayDot[a,b,{{s1,t1},{s2,t2},…}]
computes the product of arrays a and b obtained by summing up products of terms over the pairs {si,ti} of dimensions.
Details
- The arguments a and b in ArrayDot[a,b,k] should be arrays with dimensions, respectively, {m1,…,mp,d1,…,dk} and {d1,…,dk,n1,…,nq}. The result is an array c with dimensions {m1,…,mp,n1,…,nq} and ci1,…,ip,j1,…,jq
ai1,…,ip,α1,…,αkbα1,…,αk,j1,…,jq. - In ArrayDot[a,b,{{s1,t1},…,{sk,tk}}], the arguments a and b should be arrays with dimensions, respectively, {m1,…,mp} and {n1,…,nq}, where all si are distinct, all ti are distinct and for all i, 1≤si≤p, 1≤ti≤q and msinti. The result is equal to TensorContract[ab,{{s1,p+t1},…,{sk,p+tk}}].
- ArrayDot can be used on SparseArray and structured array objects.
- ArrayDot is used in the array differentiation chain rule.
Examples
open all close allBasic Examples (3)
Compute ArrayDot over two dimensions:
a = RandomReal[1, {2, 3, 4}];
b = RandomReal[1, {3, 4, 5}];
ArrayDot[a, b, 2]Compute ArrayDot over specified pairs of dimensions:
a = RandomReal[1, {2, 3, 4, 5}];
b = RandomReal[1, {5, 4, 3, 2}];
ArrayDot[a, b, {{1, 4}, {2, 3}, {3, 2}, {4, 1}}]ArrayDot is used in the array differentiation chain rule:
v = VectorSymbol["v", d];
g = MatrixSymbol["g", {m, n}];
f = ArraySymbol["f", {p, q, r}];D[f[g[v]], v]Scope (9)
a = RandomInteger[{-10, 10}, {2, 3, 4}];
b = RandomInteger[{-10, 10}, {3, 4, 5}];ArrayDot[a, b, 2]//MatrixForma = RandomReal[{-10, 10}, {2, 3, 4, 5}];
b = RandomReal[{-10, 10}, {3, 4, 5, 6, 7}];ArrayDot[a, b, 3]//MatrixForma = RandomComplex[{-10 - 10I, 10 + 10I}, {2, 3, 3}];
b = RandomComplex[{-10 - 10I, 10 + 10I}, {3, 3, 2}];ArrayDot[a, b, {{1, 3}, {2, 2}}]//MatrixForma = Array[Subscript[A, ##]&, {2, 3, 4}];
b = Array[Subscript[B, ##]&, {3, 4, 2}];ArrayDot[a, b, 2]ℱ = FiniteField[29, 4];
a = FromFiniteFieldIndex[RandomInteger[{0, 29 ^ 4 - 1}, {3, 4, 5}], ℱ];
b = FromFiniteFieldIndex[RandomInteger[{0, 29 ^ 4 - 1}, {4, 5, 3}], ℱ];
ArrayDot[a, b, 2]//MatrixFormCenteredInterval arrays:
a = Map[CenteredInterval, RandomReal[{-10, 10}, {2, 3, 4, 5}, WorkingPrecision -> 10], {4}];
b = Map[CenteredInterval, RandomReal[{-10, 10}, {3, 4, 5, 2, 3}, WorkingPrecision -> 10], {5}];
(c = ArrayDot[a, b, 3])//MatrixFormFind random representatives arep and brep of a and b:
ranrep[e_CenteredInterval] := e["Center"] + RandomInteger[{-1000, 1000}] / 1000 e["Radius"]
arep = Map[ranrep, a, {4}];
brep = Map[ranrep, b, {5}];
(crep = ArrayDot[arep, brep, 3])//MatrixFormVerify that ArrayDot[a,b,3] contains ArrayDot[arep,brep,3]:
MapThread[IntervalMemberQ, {c, crep}, 3]//MatrixFormArrayDot of sparse arrays is another sparse array:
a = SparseArray[{{i_, i_, i_} -> 1, {1, i_, i_} -> 2}, {2, 3, 4}]b = SparseArray[{{i_, i_, i_} -> 3, {1, i_, i_} -> 4}, {3, 4, 5}]ArrayDot[a, b, 2]%//MatrixForma = SymmetrizedArray[{{1, 2, 3, 4} -> 1, {2, 1, 3, 2} -> 2}, {4, 4, 4, 4}, Symmetric[{1, 2, 3}]]b = SymmetrizedArray[{{1, 2, 3, 4} -> 1, {2, 1, 3, 2} -> 2}, {4, 4, 4, 4}, Symmetric[{2, 3, 4}]]ArrayDot[a, b, 3]Efficiently multiply large arrays:
a = RandomReal[{0, 9}, {100, 100, 100}];
b = RandomComplex[1 + I, {100, 100, 100}];
ArrayDot[a, b, 2];//AbsoluteTimingApplications (1)
Approximate the determinant of a perturbed matrix:
a = RandomInteger[{-10 ^ 6, 10 ^ 6}, {7, 7}] / 10 ^ 6;
eps = RandomInteger[{-10 ^ 6, 10 ^ 6}, {7, 7}] / 10 ^ 16;t0 = Det[a];N[Det[a + eps] - t0, 20]m = MatrixSymbol["m", {7, 7}];
d1 = D[Det[m], m]t1 = t0 + ArrayDot[d1 /. m -> a, eps, 2];N[Det[a + eps] - t1, 20]d2 = D[d1, m]t2 = t1 + 1 / 2ArrayDot[ArrayDot[Normal[d2 /. m -> a], eps, 2], eps, 2];N[Det[a + eps] - t2, 20]Properties & Relations (9)
ArrayDot is linear in each argument:
a1 = RandomInteger[{-10, 10}, {2, 3, 4}];
a2 = RandomInteger[{-10, 10}, {2, 3, 4}];
b1 = RandomInteger[{-10, 10}, {3, 4, 5}];
b2 = RandomInteger[{-10, 10}, {3, 4, 5}];ArrayDot[3 a1 + 5 a2, b1, 2] === 3 ArrayDot[a1, b1, 2] + 5 ArrayDot[a2, b1, 2]ArrayDot[a1, 7b1 + 9b2, 2] === 7 ArrayDot[a1, b1, 2] + 9 ArrayDot[a1, b2, 2]Dot[a,b] is equal to ArrayDot[a,b,1]:
a = RandomInteger[{-10, 10}, {2, 3, 4}];
b = RandomInteger[{-10, 10}, {4, 3, 2}];ArrayDot[a, b, 1] === a.bSymbolicIdentityArray objects are identity elements for ArrayDot:
a = ArraySymbol["a", {m, n, p, q, r}]ArrayDot[SymbolicIdentityArray[{m, n}], a, 2]ArrayDot[a, SymbolicIdentityArray[{p, q, r}], 3]For a real matrix a, Norm[a,"Frobenius"] is equal to the square root of ArrayDot[a,a,2]:
a = RandomInteger[{-10, 10}, {5, 5}];Norm[a, "Frobenius"]Sqrt[ArrayDot[a, a, 2]]If c=ArrayDot[a,b, k], then ci1,…,ip,j1,…,jq
ai1,…,ip,α1,…,αkbα1,…,αk,j1,…,jq:
a = RandomInteger[{-10, 10}, {2, 3, 4}];
b = RandomInteger[{-10, 10}, {3, 4, 5}];ArrayDot[a, b, 2] === Table[Sum[a[[i, k, l]]b[[k, l, j]], {k, 3}, {l, 4}], {i, 2}, {j, 5}]ArrayDepth[ArrayDot[a,b,k]] is equal to ArrayDepth[a]+ArrayDepth[b]-2k:
a = RandomInteger[{-10, 10}, {2, 3, 4, 5}];
b = RandomInteger[{-10, 10}, {3, 4, 5, 6, 7}];ArrayDepth[ArrayDot[a, b, 3]] == ArrayDepth[a] + ArrayDepth[b] - 6ArrayDot can be implemented as a combination of TensorProduct and TensorContract:
a = RandomInteger[{-10, 10}, {2, 3, 4, 5}];
b = RandomInteger[{-10, 10}, {4, 5, 6, 7}];ArrayDot[a, b, 2] === TensorContract[TensorProduct[a, b], {{3, 5}, {4, 6}}]ArrayDot can be implemented as a combination of Flatten and Dot:
a = RandomInteger[{-10, 10}, {2, 3, 4, 5}];
b = RandomInteger[{-10, 10}, {4, 5, 6, 7}];ArrayDot[a, b, 2] === Flatten[a, {{1}, {2}, {3, 4}}].Flatten[b, {{1, 2}, {3}, {4}}]ArrayDot is used in the array differentiation chain rule:
a = MatrixSymbol["a", {m, n}];
b = MatrixSymbol["b", {n, m}];D[Det[a.b[x]], x]See Also
Dot TensorContract Inner D ArraySymbol SymbolicIdentityArray
Related Guides
History
Text
Wolfram Research (2024), ArrayDot, Wolfram Language function, https://reference.wolfram.com/language/ref/ArrayDot.html.
CMS
Wolfram Language. 2024. "ArrayDot." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/ArrayDot.html.
APA
Wolfram Language. (2024). ArrayDot. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/ArrayDot.html
BibTeX
@misc{reference.wolfram_2026_arraydot, author="Wolfram Research", title="{ArrayDot}", year="2024", howpublished="\url{https://reference.wolfram.com/language/ref/ArrayDot.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_arraydot, organization={Wolfram Research}, title={ArrayDot}, year={2024}, url={https://reference.wolfram.com/language/ref/ArrayDot.html}, note=[Accessed: 13-June-2026]}