-
Notifications
You must be signed in to change notification settings - Fork 18
pymath.dot
Daniel Flassig edited this page Jun 24, 2026
·
2 revisions
Vector product, matrix multiplication (or more generally contraction of two tensors)
result = pymath.dot(a, b)
result = pymath.dot(a, b, a_axis , b_axis)| Parameter | Type | Description |
|---|---|---|
a |
tensor | Left vector, matrix or tensor |
b |
tensor | Reft vector, matrix or tensor |
a_axis |
integer |
1-based position of the index of a that is contracted (summed over). Default: normal vector / matrix multiplication (last axis) |
b_axis |
integer |
1-based position of the index of a that is contracted (summed over). Default: normal vector / matrix multiplication (first axis) |
| Type | Description |
|---|---|
result |
A new vector, matrix or tensor (rank a_rank + b_rank - 2), whose axes are the non-contracted axes of t1 (in order) followed by those of t2. If both operands are vectors, the full contraction yields a single number (scalar dot product). |
- The contracted dimensions must be equal:
a'sa_axisandb'sb_axismust have the same size. -
aandbare not modified. For a function that does not allocate new tables, seepymath.dot_inplace.
For matrices A, B and vectors v and w:
-
pymath.dot(v, w)computes the vector dot productv . w -
pymath.dot(A, v)computes the matrix-vector productA . v -
pymath.dot(v, A)computes the matrix-vector productv^T . A(for pymath, row and column vectors are identical) -
pymath.dot(A, B)computes the matrix productA · B(the last axis ofAcontracted with the first axis ofB)
local A = {{1, 2},
{3, 4}}
local B = {{5, 6},
{7, 8}}
local v = {2, 5}
local w = {10, 11}
-- vector . vector -> scalar
local s = pymath.dot(v, w)
-- s == 75
-- matrix . vector (last axis of A contracted with the only axis of v)
local y = pymath.dot(A, v)
-- y == {12, 26}
-- matrix * matrix
local C = pymath.dot(A, B)
-- C == {{19, 22}, {43, 50}}
Minimum PYTHA Version: V27