How does tensor product/multiplication work?
Clash Royale CLAN TAG#URR8PPP
up vote
2
down vote
favorite
In Tensorflow, I saw the following example:
mat_a = tf.constant(np.arange(1,12, dtype=np.int32), shape=[2,2,3])
mat_b = tf.constant(np.arange(12,24, dtype=np.int32), shape=[2,3,2])
mul_c = tf.matmul(mat_a, mat_b)
with tf.Session() as sess:
runop = sess.run(mul_c)
print(runop)
[[[ 88 94]
[214 229]]
[[484 508]
[642 674]]]
How does the tensor multiplication work?
tensorflow linear-algebra
New contributor
add a comment |Â
up vote
2
down vote
favorite
In Tensorflow, I saw the following example:
mat_a = tf.constant(np.arange(1,12, dtype=np.int32), shape=[2,2,3])
mat_b = tf.constant(np.arange(12,24, dtype=np.int32), shape=[2,3,2])
mul_c = tf.matmul(mat_a, mat_b)
with tf.Session() as sess:
runop = sess.run(mul_c)
print(runop)
[[[ 88 94]
[214 229]]
[[484 508]
[642 674]]]
How does the tensor multiplication work?
tensorflow linear-algebra
New contributor
add a comment |Â
up vote
2
down vote
favorite
up vote
2
down vote
favorite
In Tensorflow, I saw the following example:
mat_a = tf.constant(np.arange(1,12, dtype=np.int32), shape=[2,2,3])
mat_b = tf.constant(np.arange(12,24, dtype=np.int32), shape=[2,3,2])
mul_c = tf.matmul(mat_a, mat_b)
with tf.Session() as sess:
runop = sess.run(mul_c)
print(runop)
[[[ 88 94]
[214 229]]
[[484 508]
[642 674]]]
How does the tensor multiplication work?
tensorflow linear-algebra
New contributor
In Tensorflow, I saw the following example:
mat_a = tf.constant(np.arange(1,12, dtype=np.int32), shape=[2,2,3])
mat_b = tf.constant(np.arange(12,24, dtype=np.int32), shape=[2,3,2])
mul_c = tf.matmul(mat_a, mat_b)
with tf.Session() as sess:
runop = sess.run(mul_c)
print(runop)
[[[ 88 94]
[214 229]]
[[484 508]
[642 674]]]
How does the tensor multiplication work?
tensorflow linear-algebra
tensorflow linear-algebra
New contributor
New contributor
edited 48 mins ago
Stephen Rauch
1,29541128
1,29541128
New contributor
asked 2 hours ago
Hendo Ley
111
111
New contributor
New contributor
add a comment |Â
add a comment |Â
3 Answers
3
active
oldest
votes
up vote
1
down vote
You may want to read the documentation.
output[..., i, j] = sum_k (a[..., i, k] * b[..., k, j]), for all indices i, j.
For instance, in your example
$~~88=1times12+2times14+3times16,~~~94=1times13+2times15+3times17$
$214=4times12+5times14+6times16,~229=4times13+5times15+6times17$
add a comment |Â
up vote
0
down vote
Tensor multiplication is just a generalization of matrix multiplication which is just a generalization of vector multiplication.
Matrix multiplication is defined as:
$$ A_i cdot B_j = C_i, j$$
where $i$ is the $i^th$ row, $j$ is the $j^th$ column, and $cdot$ is the dot product. Therefore it just a series of dot products.
One can then see how this extends to tensors:
$$mathbfA_i cdot mathbfB_j = mathbfC_i, j $$
where $i$ is the $i^th$ row-wise matrix of the tensor, and $j$ is the $j^th$ column-wise matrix of the tensor... and is therefore just a series of matrix multiplications - or a series of a series of dot products.
Assuming all tensors are of rank three(it can be described with three coordinates):
$$mathbfA otimes mathbfB = mathbfA_i, j cdot mathbfB_j, k = mathbfC_i, j, k$$
which means the $(i,j)^th$ vector of $mathbfA$ times the $(j, k)^th$ vector of $mathbfB$.
add a comment |Â
up vote
0
down vote
I'll give you a small example, if you do the following Kronecker product
beginequation
beginbmatrix
colorred1 \
colorgreen5 \
colorblue10
endbmatrix
otimes
beginbmatrix
2 \
4
endbmatrix
=
beginbmatrix
colorred1 beginbmatrix
2 \
4
endbmatrix \\
colorgreen5 beginbmatrix
2 \
4
endbmatrix \\
colorblue10 beginbmatrix
2 \
4
endbmatrix \
endbmatrix
=
beginbmatrix
2 \
4 \
10 \
20 \
20 \
40
endbmatrix
endequation
The Kronecker product works the same way for matrices as well.
New contributor
add a comment |Â
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
You may want to read the documentation.
output[..., i, j] = sum_k (a[..., i, k] * b[..., k, j]), for all indices i, j.
For instance, in your example
$~~88=1times12+2times14+3times16,~~~94=1times13+2times15+3times17$
$214=4times12+5times14+6times16,~229=4times13+5times15+6times17$
add a comment |Â
up vote
1
down vote
You may want to read the documentation.
output[..., i, j] = sum_k (a[..., i, k] * b[..., k, j]), for all indices i, j.
For instance, in your example
$~~88=1times12+2times14+3times16,~~~94=1times13+2times15+3times17$
$214=4times12+5times14+6times16,~229=4times13+5times15+6times17$
add a comment |Â
up vote
1
down vote
up vote
1
down vote
You may want to read the documentation.
output[..., i, j] = sum_k (a[..., i, k] * b[..., k, j]), for all indices i, j.
For instance, in your example
$~~88=1times12+2times14+3times16,~~~94=1times13+2times15+3times17$
$214=4times12+5times14+6times16,~229=4times13+5times15+6times17$
You may want to read the documentation.
output[..., i, j] = sum_k (a[..., i, k] * b[..., k, j]), for all indices i, j.
For instance, in your example
$~~88=1times12+2times14+3times16,~~~94=1times13+2times15+3times17$
$214=4times12+5times14+6times16,~229=4times13+5times15+6times17$
answered 1 hour ago
user12075
73427
73427
add a comment |Â
add a comment |Â
up vote
0
down vote
Tensor multiplication is just a generalization of matrix multiplication which is just a generalization of vector multiplication.
Matrix multiplication is defined as:
$$ A_i cdot B_j = C_i, j$$
where $i$ is the $i^th$ row, $j$ is the $j^th$ column, and $cdot$ is the dot product. Therefore it just a series of dot products.
One can then see how this extends to tensors:
$$mathbfA_i cdot mathbfB_j = mathbfC_i, j $$
where $i$ is the $i^th$ row-wise matrix of the tensor, and $j$ is the $j^th$ column-wise matrix of the tensor... and is therefore just a series of matrix multiplications - or a series of a series of dot products.
Assuming all tensors are of rank three(it can be described with three coordinates):
$$mathbfA otimes mathbfB = mathbfA_i, j cdot mathbfB_j, k = mathbfC_i, j, k$$
which means the $(i,j)^th$ vector of $mathbfA$ times the $(j, k)^th$ vector of $mathbfB$.
add a comment |Â
up vote
0
down vote
Tensor multiplication is just a generalization of matrix multiplication which is just a generalization of vector multiplication.
Matrix multiplication is defined as:
$$ A_i cdot B_j = C_i, j$$
where $i$ is the $i^th$ row, $j$ is the $j^th$ column, and $cdot$ is the dot product. Therefore it just a series of dot products.
One can then see how this extends to tensors:
$$mathbfA_i cdot mathbfB_j = mathbfC_i, j $$
where $i$ is the $i^th$ row-wise matrix of the tensor, and $j$ is the $j^th$ column-wise matrix of the tensor... and is therefore just a series of matrix multiplications - or a series of a series of dot products.
Assuming all tensors are of rank three(it can be described with three coordinates):
$$mathbfA otimes mathbfB = mathbfA_i, j cdot mathbfB_j, k = mathbfC_i, j, k$$
which means the $(i,j)^th$ vector of $mathbfA$ times the $(j, k)^th$ vector of $mathbfB$.
add a comment |Â
up vote
0
down vote
up vote
0
down vote
Tensor multiplication is just a generalization of matrix multiplication which is just a generalization of vector multiplication.
Matrix multiplication is defined as:
$$ A_i cdot B_j = C_i, j$$
where $i$ is the $i^th$ row, $j$ is the $j^th$ column, and $cdot$ is the dot product. Therefore it just a series of dot products.
One can then see how this extends to tensors:
$$mathbfA_i cdot mathbfB_j = mathbfC_i, j $$
where $i$ is the $i^th$ row-wise matrix of the tensor, and $j$ is the $j^th$ column-wise matrix of the tensor... and is therefore just a series of matrix multiplications - or a series of a series of dot products.
Assuming all tensors are of rank three(it can be described with three coordinates):
$$mathbfA otimes mathbfB = mathbfA_i, j cdot mathbfB_j, k = mathbfC_i, j, k$$
which means the $(i,j)^th$ vector of $mathbfA$ times the $(j, k)^th$ vector of $mathbfB$.
Tensor multiplication is just a generalization of matrix multiplication which is just a generalization of vector multiplication.
Matrix multiplication is defined as:
$$ A_i cdot B_j = C_i, j$$
where $i$ is the $i^th$ row, $j$ is the $j^th$ column, and $cdot$ is the dot product. Therefore it just a series of dot products.
One can then see how this extends to tensors:
$$mathbfA_i cdot mathbfB_j = mathbfC_i, j $$
where $i$ is the $i^th$ row-wise matrix of the tensor, and $j$ is the $j^th$ column-wise matrix of the tensor... and is therefore just a series of matrix multiplications - or a series of a series of dot products.
Assuming all tensors are of rank three(it can be described with three coordinates):
$$mathbfA otimes mathbfB = mathbfA_i, j cdot mathbfB_j, k = mathbfC_i, j, k$$
which means the $(i,j)^th$ vector of $mathbfA$ times the $(j, k)^th$ vector of $mathbfB$.
answered 17 mins ago
Daniel
1137
1137
add a comment |Â
add a comment |Â
up vote
0
down vote
I'll give you a small example, if you do the following Kronecker product
beginequation
beginbmatrix
colorred1 \
colorgreen5 \
colorblue10
endbmatrix
otimes
beginbmatrix
2 \
4
endbmatrix
=
beginbmatrix
colorred1 beginbmatrix
2 \
4
endbmatrix \\
colorgreen5 beginbmatrix
2 \
4
endbmatrix \\
colorblue10 beginbmatrix
2 \
4
endbmatrix \
endbmatrix
=
beginbmatrix
2 \
4 \
10 \
20 \
20 \
40
endbmatrix
endequation
The Kronecker product works the same way for matrices as well.
New contributor
add a comment |Â
up vote
0
down vote
I'll give you a small example, if you do the following Kronecker product
beginequation
beginbmatrix
colorred1 \
colorgreen5 \
colorblue10
endbmatrix
otimes
beginbmatrix
2 \
4
endbmatrix
=
beginbmatrix
colorred1 beginbmatrix
2 \
4
endbmatrix \\
colorgreen5 beginbmatrix
2 \
4
endbmatrix \\
colorblue10 beginbmatrix
2 \
4
endbmatrix \
endbmatrix
=
beginbmatrix
2 \
4 \
10 \
20 \
20 \
40
endbmatrix
endequation
The Kronecker product works the same way for matrices as well.
New contributor
add a comment |Â
up vote
0
down vote
up vote
0
down vote
I'll give you a small example, if you do the following Kronecker product
beginequation
beginbmatrix
colorred1 \
colorgreen5 \
colorblue10
endbmatrix
otimes
beginbmatrix
2 \
4
endbmatrix
=
beginbmatrix
colorred1 beginbmatrix
2 \
4
endbmatrix \\
colorgreen5 beginbmatrix
2 \
4
endbmatrix \\
colorblue10 beginbmatrix
2 \
4
endbmatrix \
endbmatrix
=
beginbmatrix
2 \
4 \
10 \
20 \
20 \
40
endbmatrix
endequation
The Kronecker product works the same way for matrices as well.
New contributor
I'll give you a small example, if you do the following Kronecker product
beginequation
beginbmatrix
colorred1 \
colorgreen5 \
colorblue10
endbmatrix
otimes
beginbmatrix
2 \
4
endbmatrix
=
beginbmatrix
colorred1 beginbmatrix
2 \
4
endbmatrix \\
colorgreen5 beginbmatrix
2 \
4
endbmatrix \\
colorblue10 beginbmatrix
2 \
4
endbmatrix \
endbmatrix
=
beginbmatrix
2 \
4 \
10 \
20 \
20 \
40
endbmatrix
endequation
The Kronecker product works the same way for matrices as well.
New contributor
New contributor
answered 7 mins ago
Ahmad Bazzi
1011
1011
New contributor
New contributor
add a comment |Â
add a comment |Â
Hendo Ley is a new contributor. Be nice, and check out our Code of Conduct.
Hendo Ley is a new contributor. Be nice, and check out our Code of Conduct.
Hendo Ley is a new contributor. Be nice, and check out our Code of Conduct.
Hendo Ley is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdatascience.stackexchange.com%2fquestions%2f38303%2fhow-does-tensor-product-multiplication-work%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password