[3.9] Minor improvements to the convolve() recipe (GH-24520)

This commit is contained in:
Pablo Galindo 2021-02-15 23:02:41 +00:00 committed by GitHub
parent c9f07813ab
commit 9cc70bc220
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 2 deletions

View file

@ -774,9 +774,9 @@ which incur interpreter overhead.
# convolve(data, [0.25, 0.25, 0.25, 0.25]) --> Moving average (blur)
# convolve(data, [1, -1]) --> 1st finite difference (1st derivative)
# convolve(data, [1, -2, 1]) --> 2nd finite difference (2nd derivative)
kernel = list(reversed(kernel))
kernel = tuple(kernel)[::-1]
n = len(kernel)
window = collections.deque([0] * n, maxlen=n)
window = collections.deque([0], maxlen=n) * n
for x in chain(signal, repeat(0, n-1)):
window.append(x)
yield sum(map(operator.mul, kernel, window))

View file

@ -171,6 +171,7 @@ library/ipaddress,,:db00,2001:db00::0/ffff:ff00::
library/ipaddress,,::,2001:db00::0/ffff:ff00::
library/itertools,,:step,elements from seq[start:stop:step]
library/itertools,,:stop,elements from seq[start:stop:step]
library/itertools,,::,kernel = tuple(kernel)[::-1]
library/logging.handlers,,:port,host:port
library/mmap,,:i2,obj[i1:i2]
library/multiprocessing,,`,# Add more tasks using `put()`

1 c-api/arg :ref PyArg_ParseTuple(args, "O|O:ref", &object, &callback)
171 library/ipaddress :: 2001:db00::0/ffff:ff00::
172 library/itertools :step elements from seq[start:stop:step]
173 library/itertools :stop elements from seq[start:stop:step]
174 library/itertools :: kernel = tuple(kernel)[::-1]
175 library/logging.handlers :port host:port
176 library/mmap :i2 obj[i1:i2]
177 library/multiprocessing ` # Add more tasks using `put()`