File tree 1 file changed +3
-2
lines changed
1 file changed +3
-2
lines changed Original file line number Diff line number Diff line change @@ -834,7 +834,8 @@ which incur interpreter overhead.
834
834
return chain.from_iterable(repeat(tuple(iterable), n))
835
835
836
836
def dotproduct(vec1, vec2):
837
- return sum(map(operator.mul, vec1, vec2))
837
+ "Compute a sum of products."
838
+ return sum(starmap(operator.mul, zip(vec1, vec2, strict=True)))
838
839
839
840
def convolve(signal, kernel):
840
841
# See: https://betterexplained.com/articles/intuitive-convolution/
@@ -846,7 +847,7 @@ which incur interpreter overhead.
846
847
window = collections.deque([0], maxlen=n) * n
847
848
for x in chain(signal, repeat(0, n-1)):
848
849
window.append(x)
849
- yield sum(map(operator.mul, kernel, window) )
850
+ yield dotproduct( kernel, window)
850
851
851
852
def polynomial_from_roots(roots):
852
853
"""Compute a polynomial's coefficients from its roots.
You can’t perform that action at this time.
0 commit comments