How does tensor product/multiplication work?

The name of the pictureThe name of the pictureThe name of the pictureClash 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?










share|improve this question









New contributor




Hendo Ley is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.























    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?










    share|improve this question









    New contributor




    Hendo Ley is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.





















      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?










      share|improve this question









      New contributor




      Hendo Ley is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      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






      share|improve this question









      New contributor




      Hendo Ley is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question









      New contributor




      Hendo Ley is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question








      edited 48 mins ago









      Stephen Rauch

      1,29541128




      1,29541128






      New contributor




      Hendo Ley is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked 2 hours ago









      Hendo Ley

      111




      111




      New contributor




      Hendo Ley is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      Hendo Ley is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      Hendo Ley is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.




















          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$






          share|improve this answer



























            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$.






            share|improve this answer



























              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.





              share








              New contributor




              Ahmad Bazzi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.

















                Your Answer




                StackExchange.ifUsing("editor", function ()
                return StackExchange.using("mathjaxEditing", function ()
                StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
                StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
                );
                );
                , "mathjax-editing");

                StackExchange.ready(function()
                var channelOptions =
                tags: "".split(" "),
                id: "557"
                ;
                initTagRenderer("".split(" "), "".split(" "), channelOptions);

                StackExchange.using("externalEditor", function()
                // Have to fire editor after snippets, if snippets enabled
                if (StackExchange.settings.snippets.snippetsEnabled)
                StackExchange.using("snippets", function()
                createEditor();
                );

                else
                createEditor();

                );

                function createEditor()
                StackExchange.prepareEditor(
                heartbeatType: 'answer',
                convertImagesToLinks: false,
                noModals: false,
                showLowRepImageUploadWarning: true,
                reputationToPostImages: null,
                bindNavPrevention: true,
                postfix: "",
                noCode: true, onDemand: true,
                discardSelector: ".discard-answer"
                ,immediatelyShowMarkdownHelp:true
                );



                );






                Hendo Ley is a new contributor. Be nice, and check out our Code of Conduct.









                 

                draft saved


                draft discarded


















                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






























                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$






                share|improve this answer
























                  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$






                  share|improve this answer






















                    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$






                    share|improve this answer












                    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$







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered 1 hour ago









                    user12075

                    73427




                    73427




















                        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$.






                        share|improve this answer
























                          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$.






                          share|improve this answer






















                            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$.






                            share|improve this answer












                            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$.







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered 17 mins ago









                            Daniel

                            1137




                            1137




















                                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.





                                share








                                New contributor




                                Ahmad Bazzi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                Check out our Code of Conduct.





















                                  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.





                                  share








                                  New contributor




                                  Ahmad Bazzi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                  Check out our Code of Conduct.



















                                    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.





                                    share








                                    New contributor




                                    Ahmad Bazzi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                    Check out our Code of Conduct.









                                    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.






                                    share








                                    New contributor




                                    Ahmad Bazzi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                    Check out our Code of Conduct.








                                    share


                                    share






                                    New contributor




                                    Ahmad Bazzi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                    Check out our Code of Conduct.









                                    answered 7 mins ago









                                    Ahmad Bazzi

                                    1011




                                    1011




                                    New contributor




                                    Ahmad Bazzi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                    Check out our Code of Conduct.





                                    New contributor





                                    Ahmad Bazzi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                    Check out our Code of Conduct.






                                    Ahmad Bazzi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                    Check out our Code of Conduct.




















                                        Hendo Ley is a new contributor. Be nice, and check out our Code of Conduct.









                                         

                                        draft saved


                                        draft discarded


















                                        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.













                                         


                                        draft saved


                                        draft discarded














                                        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













































































                                        Comments

                                        Popular posts from this blog

                                        What does second last employer means? [closed]

                                        Installing NextGIS Connect into QGIS 3?

                                        One-line joke