Note that there are some explanatory texts on larger screens.

plurals
  1. POPython scipy.numpy.convolve and scipy.signal.fftconvolve different results
    primarykey
    data
    text
    <p>i am having 2 arrays (G and G_). They have the same shape and size and i want to convolve them. i found the numpy.convolve and fftconvolve. My Code is like:</p> <pre><code>foldedX = getFoldGradientsFFT(G, G_) foldedY = getFoldGradientsNumpy(G, G_) def getFoldGradientsFFT(G, G_): # convolve via scipy fast fourier transform X =signal.fftconvolve(G,G_, "same) X*=255.0/numpy.max(X); return X def getFoldGradientsNumpy(G, G_): # convolve via numpy.convolve Y = ndimage.convolve(G, G_) Y*=255.0/numpy.max(Y); return Y </code></pre> <p>But the results aren't the same. The result is like: Numpy.concolve()</p> <pre><code>[ 11.60287582 3.28262652 18.80395211 52.75829556 99.61675945 147.74124258 187.66178244 215.06160439 234.1907606 229.04221552] </code></pre> <p>scipy.signal.fftconvolve:</p> <pre><code>[ -4.88130620e-15 6.74371119e-02 4.91875539e+00 1.94250997e+01 3.88227012e+01 6.70322921e+01 9.78460423e+01 1.08486302e+02 1.17267015e+02 1.15691562e+02] </code></pre> <p>I thought the result is supposed to be the same, even if the two functions convolves with a different procedure?!</p> <hr> <p>i forgot to mention, that i want to convolve 2 2-dimensional arrays :S the arrays:</p> <pre><code>G = array([[1,2],[3,4]]) G_ = array([[5,6],[7,8]]) </code></pre> <p>the code</p> <pre><code>def getFoldGradientsFFT(G, G_): X =signal.fftconvolve(G,G_,"same") X=X.astype("int") X*=255.0/np.max(X); return X def getFoldGradientsNumpy(G, G_): # convolve via convolve old_shape = G.shape G = np.reshape(G, G.size) G_ = np.reshape(G_, G.size) Y = np.convolve(G, G_, "same") Y = np.reshape(Y,old_shape) Y = Y.astype("int") Y*=255.0/np.max(Y); return Y def getFoldGradientsNDImage(G, G_): Y = ndimage.convolve(G, G_) Y = Y.astype("int") Y *= 255.0/np.max(Y) return Y </code></pre> <p>the results:</p> <pre><code>getFoldGradientsFFT [[ 21 68] [ 93 255]] getFoldGradientsNumpy [[ 66 142] [250 255]] getFoldGradientsNDImage [[147 181] [220 255]] </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload