-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmaxpool1d.py
More file actions
29 lines (26 loc) · 955 Bytes
/
maxpool1d.py
File metadata and controls
29 lines (26 loc) · 955 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
def maxpool1d(lst, pool_size, no_pad=True, stride=None):
result = []
if not no_pad and len(lst) % pool_size != 0:
pad = len(lst) % pool_size
for _ in range(pad):
lst.append(0)
print("input with pad ", lst)
if stride is None:
stride = pool_size
for i in range(0, len(lst)-pool_size+1, stride):
window = lst[i:i+pool_size]
maxi = max(window)
result.append(maxi)
return result
lst = [2, 4, 1, 5, 3, 8, 7, 6]
result = maxpool1d(lst, pool_size=3, no_pad = True, stride=2)
print(result) # Output: [4, 5, 8]
lst = [2, 4, 1, 5, 3, 8, 7, 6]
result = maxpool1d(lst, pool_size=3, no_pad = True)
print(result) # Output: [4, 8]
lst = [2, 4, 1, 5, 3, 8, 7, 6]
result = maxpool1d(lst, pool_size=3, no_pad = False, stride=2)
print(result) # Output: [4, 5, 8, 7]
lst = [2, 4, 1, 5, 3, 8, 7, 6]
result = maxpool1d(lst, pool_size=3, no_pad = False)
print(result) # Output: [4, 8, 7]