[Numpy-discussion] Possible bug in Numpy.convolve

Thøger Emil Rivera-Thorsen thoger.emil at gmail.com
Wed Mar 22 22:06:02 EDT 2017


Dear list;

I am honestly not certain whether this, or the SciPy list, is the 
appropriate place to post this; please let me know if I got it wrong.

I am convolving a 1D data set containing a relatively narrow peak, with 
a relatively narrow Gaussian kernel, in order to emulate the effect of 
atmospheric seeing on astrophysical observations.

I have a 1D data array 45 pixels long, and a Gaussian kernel, and run 
np.convolve(data, kernel, mode='same') on the two arrays, the resulting 
array's peak is shifted relative to the origin. I have attached a plot 
to illustrate.

The original data is shown in blue. When I convolve it with a symmetric 
kernel (black), I get an offset resulting peak (magenta). If I flip the 
kernel -- even though it is perfectly symmetric -- the resulting curve 
is offset in the opposite direction (yellow). However, if I offset the 
kernel so it is centered exactly one pixel below the central value, the 
output array gets centered correct (red), even if I flip the (now no 
longer symmetric) kernel.

This is using Numpy 1.11.3, python 2.7.13, on Anaconda 4.3.0 64-bit on 
Ubuntu 16.10

Using astropy.convolution, reproduces the correct red curve, so I can 
use that for now, but it seems to me this is either a bug or, if it is 
indeed the intended behavior, a word of caution would be merited in the 
docstring.

Cheers,

Emil Rivera-Thorsen


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20170323/a6e1fc86/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: cjlfglpfehnobnll.png
Type: image/png
Size: 32973 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20170323/a6e1fc86/attachment.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Selection_043.png
Type: image/png
Size: 32973 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20170323/a6e1fc86/attachment-0001.png>


More information about the NumPy-Discussion mailing list