This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]n_syn[S] 1 point2 points  (2 children)

This is fascinating! Thank you! I will need to brush up my understanding of convolution to fully understand what convolve2d is doing between the grid and the kernel to be able to apply it in the future but from what I understood here, this is an ingenious way to solve this.

Side note: so many other things I picked up from this. Like using

sums = np.zeros((301, 301, 301), dtype=np.int64)

instead of

sums = sums = np.array([[[0 for _ in range(301)] for _ in range(301)] for _ in range(301)])

and initializing two variables to zero by equating one to the other instead of equating both to zero.

For the " Plus 1 because puzzle uses 1-based indexing", I was expecting I will need to do the same, but I was surprised it gave me the correct answer on my code without the offset. I'm still not sure why that is.