Let's say I have a 100x100x100x100 numpy array. I'm trying to apply np.correlate
of this array with itself but to only one of its axes, say axes 1. In an ideal world, this would be something like
print(a.shape) # (100,100,100,100)
correlated = np.correlate(a, a, "full", axis=1)
print(correlated.shape) # (100,199,100,100)
So basically the same behavior of np.fft
, but with correlate. I can iterate over all the other dimensions and then calculate the correlation at each step, but these arrays can get pretty big and this would become very slow.
Is there a Numpy way of doing this that is faster? I tried using apply_over_axes
but apparently it's not possible. And also, apply_over_axes
, vectorize
, etc are just python loops under the hood, so I guess that wouldn't much of an advantage anyway.