Inside-Deep-Learning icon indicating copy to clipboard operation
Inside-Deep-Learning copied to clipboard

Sliding filter, Code snippet in Chapter 3.2.1

Open benjwolff opened this issue 2 years ago • 1 comments

In Chapter 3.2.1, there is an implementation of sliding the filter over the input:

filter = [1, 0, -1]
input = [1, 0, 2, -1, 1, 2]
output = []
for i in range(len(input) - len(filter)):
    result = 0
    for j in range(len(filter)):
        result += input[i+j] * filter[j]
    output.append(result) 

The first loop does not catch the last possible slide, so it should be:

filter = [1, 0, -1]
input = [1, 0, 2, -1, 1, 2]
output = []
for i in range(len(input) - len(filter) + 1):
    result = 0
    for j in range(len(filter)):
        result += input[i+j] * filter[j]
    output.append(result) 

PS: @EdwardRaff your book is absolutely brilliant!

benjwolff avatar Jul 20 '23 08:07 benjwolff

Glad you are enjoying it despite some typos! :)

EdwardRaff avatar Jul 21 '23 14:07 EdwardRaff