I have two numpy arrays:
Divakar gives the best (most efficient) answers. For completeness' sake, one other way of doing it is by using Numpy's broadcasting capabilities:
(t[:,np.newaxis,np.newaxis]*I).sum(axis=0)
By adding two axes to t
, broadcasting becomes possible and one can use regular Numpy operations, which for some might be more readable.