脾气暴躁-不可能执行带有3个矩阵的矩阵乘积

时间:2019-02-23 17:30:42

标签: python numpy matrix-multiplication

我有3个Followig矩阵:

      matrix1 = np.array(eval(der_input_LU[j]));
      submatrix1 = matrix1[0:100][0:4]
      matrix2 = invCrossMatrix
      matrix3 = np.array(eval(der_input_LU[l]));
      submatrix3 = matrix3[0:4][0:100];     

每个形状:

      print 'shape matrix1 = ', submatrix1.shape
      print 'shape matrix2 = ', matrix2.shape
      print 'shape matrix3 = ', submatrix3.shape

打印:

shape submatrix1 =  (4, 100)
shape matrix2 =  (4, 4)
shape submatrix3 =  (4, 100)

我正在寻找这3个矩阵之间的矩阵积。我试图像这样使用np.linalg.multi_dot

matFinal = np.linalg.multi_dot([submatrix1,matrix2,submatrix3])

但是出现以下错误:

invCrossMatrix =  [[ 2.76704670e-09  0.00000000e+00  0.00000000e+00  0.00000000e+00]
 [ 0.00000000e+00  6.82633333e-06 -1.65769406e-19 -2.12753150e-12]
 [ 0.00000000e+00 -1.65769406e-19  6.82633333e-06 -3.31538864e-19]
 [ 0.00000000e+00 -2.12753150e-12 -3.31538864e-19  1.36526667e-05]]
Traceback (most recent call last):
  File "program1.py", line 1497, in <module>
    map(integ_LU_cross, g_LU(i))
  File "program1.py", line 1436, in integ_LU_cross
    function_A = aux_fun_LU_cross(way, ecs, I1[0], I1[1], I1[2])
  File "program1.py", line 1369, in aux_fun_LU_cross
    submatrix3 = matrix3[0:4][0:100];          
IndexError: too many indices for array

如您所见,我尝试遵守以下命令:(100,4)*(4,4)*(4,100),但不起作用。

为了使用multi_dot函数,我是否尊重正确的尺寸? 我找不到错误的出处。

欢迎提出任何建议或意见,

0 个答案:

没有答案