Hasnain
Hasnain

Reputation: 73

Tensor multiplication of Rank 3

I have two tensors of rank 3 each, in other words two 3D matrix. I want to take dot product of these two matrix. I am confused to continue with this problem. Help me out with formula to do so.

Upvotes: 0

Views: 4863

Answers (2)

Car Loz
Car Loz

Reputation: 123

The vector inner product sum the elementwise products. The tensor inner product follows the same idea. Match the elements, multiply them, and add them all .

Upvotes: 0

kmario23
kmario23

Reputation: 61435

A 3-way tensor (or equivalently 3D array or 3-order array) need not necessarily be of rank-3; Here, "rank of a tensor" means the minimum number of rank-1 tensors (i.e. outer product of vectors; For N-way tensor, it's the outer product of N vectors) needed to get your original tensor. This is explained in the below figure of so-called CP decomposition.

tensor-rank and CP decomposition

In the above figure, the original tensor(x) can be written as a sum of R rank-1 tensors, where R is a positive integer. In CP decomposition, we aim to find a minimum R that yields our original tensor X. And this minimum R is called the rank of our original tensor.

For a 3-way tensor, it is the minimum number of (a1,a2,a3...aR; b1,b2,b3...bR; c1,c2,c3...cR) vectors (where each of the vectors is n dimensional) required to obtain the original tensor. The tensor can be written as the outer product of these vectors as: 3-way tensor 3-way tensor explanation

In terms of element-wise, we can write the 3-way tensor as:

3-way element-wise

Now, with that background, to answer your specific question, to take the dot product (also called tensor inner product), both tensors must be of same shape (for e.g. 3x2x5 and 3x2x5), then the inner product is defined as the sum of the element-wise product of their values.

Tensor inner (or dot) product

where the script X and Y are the same-shape tensors.


P.S.: The tilde in the above formulae should not be interpreted as an approximation.

Upvotes: 3

Related Questions