scipy convolve2d gibt falsche Werte aus

Hier ist mein Code, mit dem ich die Richtigkeit von convolve2d überprüft habe

import numpy as np
from scipy.signal import convolve2d

X = np.random.randint(5, size=(10,10))
K = np.random.randint(5, size=(3,3))
print "Input's top-left corner:"
print X[:3,:3]
print 'Kernel:'
print K

print 'Hardcording the calculation of a valid convolution (top-left)'
print (X[:3,:3]*K)
print 'Sums to'
print (X[:3,:3]*K).sum()
print 'However the top-left value of the convolve2d result'
Y = convolve2d(X, K, 'valid')
print Y[0,0]

Auf meinem Computer führt dies zu folgenden Ergebnissen:

Input's top-left (3x3) corner:
[[0 0 0]
 [1 1 2]
 [1 3 0]]
Kernel:
[[4 1 1]
 [0 3 3]
 [2 1 2]]
Hardcording the calculation of a valid convolution (top-left)
[[0 0 0]
 [0 3 6]
 [2 3 0]]
Sums to
14
However the top-left value of the convolve2d result
10

Hintergrundgeschicht: Ich habe eine Convnet-Bibliothek debuggt und irgendwie waren die Verläufe immer falsch. Nach ein paar Wochen kam ich zu dem Schluss, dass alles gut funktionieren sollte, und überprüfte die Funktion von convolve2d mit bloßer Hand.

Antworten auf die Frage(4)

Ihre Antwort auf die Frage