Vectorize large NumPy multiplication

前端 未结 2 441
醉酒成梦
醉酒成梦 2021-01-18 21:18

I am interested in calculating a large NumPy array. I have a large array A which contains a bunch of numbers. I want to calculate the sum of different combinati

2条回答
  •  [愿得一人]
    2021-01-18 21:37

    Instead of dot you could use tensordot. Your current method is equivalent to:

    np.tensordot(A, Combinations, [2, 1]).transpose(2, 0, 1)
    

    Note the transpose at the end to put the axes in the correct order.

    Like dot, the tensordot function can call down to the fast BLAS/LAPACK libraries (if you have them installed) and so should be perform well for large arrays.

提交回复
热议问题