Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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:'
- 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]
- Input:
- [[4 1 4]
- [3 3 3]
- [3 4 0]]
- Kernel:
- [[1 3 0]
- [0 2 2]
- [2 1 3]]
- Hardcording the calculation of a valid convolution (top-left)
- [[4 3 0]
- [0 6 6]
- [6 4 0]]
- Sums to
- 29
- However the top-left value of the result
- 45
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement