Skip to content

Commit 22249d6

Browse files
committed
Update itertools recipe to reflect the promotion.
1 parent 9b1edcc commit 22249d6

1 file changed

Lines changed: 2 additions & 6 deletions

File tree

Doc/library/itertools.rst

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ by combining :func:`map` and :func:`count` to form ``map(f, count())``.
3333
These tools and their built-in counterparts also work well with the high-speed
3434
functions in the :mod:`operator` module. For example, the multiplication
3535
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)))``.
3737

3838

3939
**Infinite iterators:**
@@ -838,10 +838,6 @@ which incur interpreter overhead.
838838
"Returns the sequence elements n times"
839839
return chain.from_iterable(repeat(tuple(iterable), n))
840840

841-
def dotproduct(vec1, vec2):
842-
"Compute a sum of products."
843-
return sum(starmap(operator.mul, zip(vec1, vec2, strict=True)))
844-
845841
def convolve(signal, kernel):
846842
# See: https://betterexplained.com/articles/intuitive-convolution/
847843
# convolve(data, [0.25, 0.25, 0.25, 0.25]) --> Moving average (blur)
@@ -852,7 +848,7 @@ which incur interpreter overhead.
852848
window = collections.deque([0], maxlen=n) * n
853849
for x in chain(signal, repeat(0, n-1)):
854850
window.append(x)
855-
yield dotproduct(kernel, window)
851+
yield math.sumprod(kernel, window)
856852

857853
def polynomial_from_roots(roots):
858854
"""Compute a polynomial's coefficients from its roots.

0 commit comments

Comments
 (0)