@@ -33,7 +33,7 @@ by combining :func:`map` and :func:`count` to form ``map(f, count())``.
33
33
These tools and their built-in counterparts also work well with the high-speed
34
34
functions in the :mod: `operator ` module. For example, the multiplication
35
35
operator can be mapped across two vectors to form an efficient dot-product:
36
- ``sum(map (operator.mul, vector1, vector2 )) ``.
36
+ ``sum(starmap (operator.mul, zip(vec1, vec2, strict=True) )) ``.
37
37
38
38
39
39
**Infinite iterators: **
@@ -799,7 +799,7 @@ which incur interpreter overhead.
799
799
"Returns the sequence elements n times"
800
800
return chain.from_iterable(repeat(tuple(iterable), n))
801
801
802
- def dotproduct (vec1, vec2):
802
+ def sumprod (vec1, vec2):
803
803
"Compute a sum of products."
804
804
return sum(starmap(operator.mul, zip(vec1, vec2, strict=True)))
805
805
@@ -813,7 +813,7 @@ which incur interpreter overhead.
813
813
window = collections.deque([0], maxlen=n) * n
814
814
for x in chain(signal, repeat(0, n-1)):
815
815
window.append(x)
816
- yield dotproduct (kernel, window)
816
+ yield sumprod (kernel, window)
817
817
818
818
def polynomial_from_roots(roots):
819
819
"""Compute a polynomial's coefficients from its roots.
@@ -1181,7 +1181,7 @@ which incur interpreter overhead.
1181
1181
>>> list (ncycles(' abc' , 3 ))
1182
1182
['a', 'b', 'c', 'a', 'b', 'c', 'a', 'b', 'c']
1183
1183
1184
- >>> dotproduct ([1 ,2 ,3 ], [4 ,5 ,6 ])
1184
+ >>> sumprod ([1 ,2 ,3 ], [4 ,5 ,6 ])
1185
1185
32
1186
1186
1187
1187
>>> data = [20 , 40 , 24 , 32 , 20 , 28 , 16 ]
0 commit comments