I’m trying to convolve two probability maps in Python with numpy.convolve, and decided to use mode=’same’ so that I could plot the convolution against the original distributions. However, my convolution doesn’t seem to be in the correct place, as I would expect its peak to lie between distributions A and B (see figure), or at the very least at a higher value of x than it is now. When I try using mode=’full’, the convolution occurs in a different place on the x-axis, but still does not occur where I would expect it. The location of the convolution in relation to the original arrays is very important to what I’m doing, so needs to occur between the other two distributions (provided by understanding of maths is right). I don’t know why this isn’t happening, so does anyone know how to fix it? Any help would be greatly appreciated!
A plot of probability distributions A and B, and their convolution with mode=’same’
A plot of the convolution of A and B with mode=’full’
This is the code I’m using (my two input arrays are very long so I’ve left them out can I can probably find a way to supply them if it would help):
import numpy as np
import matplotlib.pyplot as plt
x1=np.arange(len(GRB_240612A))
x2=np.arange(len(GRB_240612B))
if len(x1)==len(x2):
x=x1
convolution=np.convolve(GRB_240612A, GRB_240612B, mode='same')
plt.plot(x, GRB_240612A, label='A')
plt.plot(x, GRB_240612B, label='B')
plt.plot(x, convolution, label='Convolution of A and B')
plt.legend()
plt.xlim(0)
plt.ylim(0)
plt.show()
Jacob Ayre is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.