Reputation: 55
I want to convolve two same-dimension matrices using numpy. According to the example on wikipedia this is a possible operation.
import numpy as np
f = np.array([[45, 60, 98],
[46, 65, 98],
[47, 65, 96]])
h = np.array([[ 0.1, 0.1, 0.1],
[ 0.1, 0.2, 0.1],
[ 0.1, 0.1, 0.1]])
print np.convolve(f,h)
Why am I getting this error?
Upvotes: 1
Views: 1015
Reputation: 2916
try:
import scipy.signal
import numpy as np
f = np.array([[45, 60, 98],
[46, 65, 98],
[47, 65, 96]])
h = np.array([[ 0.1, 0.1, 0.1],
[ 0.1, 0.2, 0.1],
[ 0.1, 0.1, 0.1]])
print scipy.signal.convolve2d(f, h, 'valid')
It should implement the convolution described in your image.
The output is np.array([[ 74.5]])
Upvotes: 3