Python - Matrix outer product

后端 未结 4 1410
时光取名叫无心
时光取名叫无心 2020-12-14 10:54

Given two matrices

A: m * r
B: n * r

I want to generate another matrix C: m * n, with each entry C_ij being a mat

4条回答
  •  天命终不由人
    2020-12-14 11:46

    The Einstein notation expresses this problem nicely

    In [85]: np.einsum('ac,bd->abcd',A,B)
    Out[85]: 
    array([[[[ 3,  1],
             [ 6,  2]],
    
            [[ 1,  2],
             [ 2,  4]]],
    
    
           [[[ 9,  3],
             [12,  4]],
    
            [[ 3,  6],
             [ 4,  8]]]])
    

提交回复
热议问题