mirror of
https://github.com/python/cpython.git
synced 2025-12-23 09:19:18 +00:00
[3.9] Minor improvements to the convolve() recipe (GH-24520)
This commit is contained in:
parent
c9f07813ab
commit
9cc70bc220
2 changed files with 3 additions and 2 deletions
|
|
@ -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))
|
||||
|
|
|
|||
|
|
@ -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()`
|
||||
|
|
|
|||
|
Loading…
Add table
Add a link
Reference in a new issue