Multiply a 3D matrix with a 2D matrix

前端 未结 10 1207
盖世英雄少女心
盖世英雄少女心 2020-11-28 09:29

Suppose I have an AxBxC matrix X and a BxD matrix Y.

Is there a non-loop method by which I can multiply

相关标签:
10条回答
  • 2020-11-28 10:08

    I would think recursion, but that's the only other non- loop method you can do

    0 讨论(0)
  • 2020-11-28 10:10

    You could "unroll" the loop, ie write out all the multiplications sequentially that would occur in the loop

    0 讨论(0)
  • 2020-11-28 10:11

    As a personal preference, I like my code to be as succinct and readable as possible.

    Here's what I would have done, though it doesn't meet your 'no-loops' requirement:

    for m = 1:C
    
        Z(:,:,m) = X(:,:,m)*Y;
    
    end
    

    This results in an A x D x C matrix Z.

    And of course, you can always pre-allocate Z to speed things up by using Z = zeros(A,D,C);.

    0 讨论(0)
  • 2020-11-28 10:11

    Nope. There are several ways, but it always comes out in a loop, direct or indirect.

    Just to please my curiosity, why would you want that anyway ?

    0 讨论(0)
提交回复
热议问题