[Scipy-tickets] [SciPy] #1411: scipy.signal.correlate gives different results than numpy.correlate

SciPy Trac scipy-tickets@scipy....
Sun Mar 20 16:14:46 CDT 2011

#1411: scipy.signal.correlate gives different results than numpy.correlate
 Reporter:  jpaalasm      |       Owner:  somebody
     Type:  defect        |      Status:  new     
 Priority:  normal        |   Milestone:  0.10.0  
Component:  scipy.signal  |     Version:  0.9.0   
 Keywords:                |  

Comment(by warren.weckesser):

 The relevant block of code is
     if mode == 'valid':
         ps = [i - j + 1 for i, j in zip(in1.shape, in2.shape)]
         out = np.empty(ps, in1.dtype)
         for i in range(len(ps)):
             if ps[i] <= 0:
                 raise ValueError("Dimension of x(%d) < y(%d) " \
                                  "not compatible with valid mode" % \
                                  (in1.shape[i], in2.shape[i]))

         z = sigtools._correlateND(in1, in2, out, val)
 The bug is the creation of the array 'out' before checking the values in
 ps.  The quick fix is to move the line "out = np.empty(ps, in1.dtype)" to
 after the loop that checks for negative values in ps.  Then one would get
 the intended error message.

 The bigger question is: why does the first argument have to have more
 elements than the second?  The docstring doesn't say anything about this.
 As pointed out in the description, numpy's correlate() handles either
 order, and so does scipy's correlate if mode='full'.  Shouldn't
 mode='valid' just be the appropriate subset of the 'full' case?

Ticket URL: <http://projects.scipy.org/scipy/ticket/1411#comment:1>
SciPy <http://www.scipy.org>
SciPy is open-source software for mathematics, science, and engineering.

More information about the Scipy-tickets mailing list