The speed of python code can be very slow compared to other languages ββlike c. numpy
aims to provide high-performance operations on arrays, so the developers decided to implement some operations in c
.
Unfortunately, it will not find the python correlate
implementation in the numpy
database, but if you are familiar with the c
and python
extension modules, you can find the corresponding code here .
In different modes, the length of the output array is indicated. You can simulate them by transforming your inputs:
import numpy as np a = [1, 2, 3] v = [0, 1, 0.5] np.correlate(a, v, mode="full")
returns:
array([ 0.5, 2. , 3.5, 3. , 0. ])
You can get the same result by filling v
zeros:
np.correlate(a, [0, 0] + v + [0, 0])
returns the same result:
array([ 0.5, 2. , 3.5, 3. , 0. ])
source share