Reputation: 45
Suppose I have two 1d arrays with same length(saying n),and now I want to implement a "cumdot" function,which output 1d array with length n and can be implemented in pure python code
def cumdot(a,b):#a,b are two 1d arrays with same length
n = len(a)
output = np.empty(n)
for i in range(n):
output[i] = np.dot(a[:i+1],b[:i+1])
return output
How can I implement the "cumdot" function more efficiently?
Upvotes: 2
Views: 185
Reputation: 3059
I think by pure python you mean: using core of python!
def comdot(a, b):
result = [i[0]*i[1] for i in zip(a, b)]
return result
Upvotes: -1