您可以使用np.tensordot -
np.tensordot(t,I, axes=([0],[0]))
您还可以使用np.einsum -
np.einsum('i,ijk->jk',t,I)
运行时测试和输出验证 -
In [21]: def original_app(t,I):
...: tI = np.asarray([t[i]*I[i,:,:] for i in range(t.shape[0])])
...: tsum = np.sum(tI,axis=0)
...: return tsum
...:
In [22]: # Inputs with random elements
...: t = np.random.rand(70,)
...: I = np.random.rand(70,1024,1024)
...:
In [23]: np.allclose(original_app(t,I),np.tensordot(t,I, axes=([0],[0])))
Out[23]: True
In [24]: np.allclose(original_app(t,I),np.einsum('i,ijk->jk',t,I))
Out[24]: True
In [25]: %timeit np.tensordot(t,I, axes=([0],[0]))
1 loops, best of 3: 110 ms per loop
In [26]: %timeit np.einsum('i,ijk->jk',t,I)
1 loops, best of 3: 201 ms per loop