[SciPy-user] Correlate Times?

Johann Cohen-Tanugi cohen@slac.stanford....
Thu Jan 17 20:12:10 CST 2008


hi Ryan, I see the same effect on my box (I actually lost patience and 
killed SS). Note that you forgot an "import numpy as N".
Anyway  :
In [15]: ?N.correlate
Type:           function
Base Class:     <type 'function'>
String Form:    <function correlate at 0x8bd1064>
Namespace:      Interactive
File:           /usr/lib/python2.5/site-packages/numpy/core/numeric.py
Definition:     N.correlate(a, v, mode='valid')
Docstring:
    Return the discrete, linear correlation of 1-D sequences a and v; mode
    can be 'valid', 'same', or 'full' to specify the size of the resulting
    sequence


In [16]: ?S.correlate
Type:           function
Base Class:     <type 'function'>
String Form:    <function correlate at 0x8bd1064>
Namespace:      Interactive
File:           /usr/lib/python2.5/site-packages/numpy/core/numeric.py
Definition:     S.correlate(a, v, mode='valid')
Docstring:
    Return the discrete, linear correlation of 1-D sequences a and v; mode
    can be 'valid', 'same', or 'full' to specify the size of the resulting
    sequence

In [19]: ?SS.correlate
Type:           function
Base Class:     <type 'function'>
String Form:    <function correlate at 0x8ea341c>
Namespace:      Interactive
File:           /usr/lib/python2.5/site-packages/scipy/signal/signaltools.py
Definition:     SS.correlate(in1, in2, mode='full')
Docstring:
    Cross-correlate two N-dimensional arrays.
   
    Description:
   
       Cross-correlate in1 and in2 with the output size determined by mode.
   
    Inputs:
   
      in1 -- an N-dimensional array.
      in2 -- an array with the same number of dimensions as in1.
      mode -- a flag indicating the size of the output
              'valid'  (0): The output consists only of those elements that
                              do not rely on the zero-padding.
              'same'   (1): The output is the same size as the largest input
                              centered with respect to the 'full' output.
              'full'   (2): The output is the full discrete linear
                              cross-correlation of the inputs. (Default)
   
    Outputs:  (out,)
   
      out -- an N-dimensional array containing a subset of the discrete 
linear
             cross-correlation of in1 with in2.


So, S calls N.correlate, and it is a 1D array function, while SS accepts 
N-dim array.
Nevertheless, the cost when the array is 1D is strange for SS, and if it 
is a feature, it should maybe check array dim and default to the numpy 
implementation when 1D....

best,
Johann

Ryan May wrote:
> Hey,
>
> Can someone explain this to me?
>
> In [3]: import scipy as S
>
> In [5]: import scipy.signal as SS
>
> In [6]: from numpy.random import rand
>
> In [7]: up = rand(18000)
>
> In [10]: %timeit N.correlate(up,up,mode='full')
> 10 loops, best of 3: 829 ms per loop
>
> In [11]: %timeit S.correlate(up,up,mode='full')
> 10 loops, best of 3: 827 ms per loop
>
> In [12]: %timeit SS.correlate(up,up,mode='full')
> 10 loops, best of 3: 11.5 s per loop
>
> Is this a configuration problem?  If not, why does
> scipy.signal.correlate even exist?
>
> Thanks,
>
> Ryan
>
>   


More information about the SciPy-user mailing list