Created
March 20, 2023 18:08
-
-
Save hexgnu/050b32838d27a1291d391d950b77820f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
def conv1d(input_array, input_filter): | |
window_size = len(input_filter) | |
window_norm = math.sqrt(sum([x**2 for x in input_filter])) | |
output_array = [] | |
for i in range(window_size, len(input_array) + 1): | |
cur_window = input_array[(i - window_size):i] | |
cur_norm = math.sqrt(sum([x**2 for x in cur_window])) | |
cur_dot = sum( | |
[ | |
(x / cur_norm) * (y / window_norm) | |
for x, y in zip(cur_window, input_filter) | |
] | |
) | |
output_array.append(cur_dot) | |
return output_array | |
def match(input_array, input_filter): | |
return any( | |
map( | |
lambda x: (x - 1) ** 2 < 1e-10, | |
conv1d(input_array, input_filter) | |
) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment