@@ -33,7 +33,7 @@ by combining :func:`map` and :func:`count` to form ``map(f, count())``.
3333These tools and their built-in counterparts also work well with the high-speed
3434functions in the :mod: `operator ` module. For example, the multiplication
3535operator 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.
@@ -1211,9 +1207,6 @@ which incur interpreter overhead.
12111207 >>> list (ncycles(' abc' , 3 ))
12121208 ['a', 'b', 'c', 'a', 'b', 'c', 'a', 'b', 'c']
12131209
1214- >>> dotproduct([1 ,2 ,3 ], [4 ,5 ,6 ])
1215- 32
1216-
12171210 >>> data = [20 , 40 , 24 , 32 , 20 , 28 , 16 ]
12181211 >>> list (convolve(data, [0.25 , 0.25 , 0.25 , 0.25 ]))
12191212 [5.0, 15.0, 21.0, 29.0, 29.0, 26.0, 24.0, 16.0, 11.0, 4.0]
0 commit comments