Suppose i have an input of n arrays with the shape k*k. Now i want to sum them together but also move the k*k array by some positiv integer (step) after each operation.
Its hard to actually explain it so heres a litle drawing.
at every part where the k*k arrays intersect they are just summed up.
my current way to implement it looks like this:
import numpy as np
# some input with shape (n ,k ,k)
x = np.arange(16).reshape(4 ,2 ,2)
# im intializing the output to zeros in the beginning and
# add the k*k windows to it
out = np.zeros((2 ,5))
# loops over the (n ,k ,k) input and adds the values
# to the output and shifts by 1 to the right
for i in range(4):
# i could also be multipied by any integer to move
# the window by more then one
out[: ,i+0:i+2] += x[i]
so my question is if its possible to get rid of the loop or if you could use some builtin numpy function to accelerate this or more general a way to make it faster when the size of the input grows.
thanks for reading and have a nice day :)
