Multiply several matrices in numpy

前端 未结 5 2152
借酒劲吻你
借酒劲吻你 2021-02-02 06:52

Suppose you have n square matrices A1,...,An. Is there anyway to multiply these matrices in a neat way? As far as I know dot in numpy accepts only two arguments. One obvious way

5条回答
  •  春和景丽
    2021-02-02 07:18

    A_list = [np.random.randn(100, 100) for i in xrange(10)]
    B = np.eye(A_list[0].shape[0])
    for A in A_list:
        B = np.dot(B, A)
    
    C = reduce(np.dot, A_list)
    
    assert(B == C)
    

提交回复
热议问题