Advertisement
Guest User

Untitled

a guest
Oct 25th, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. import numpy as np
  2. from scipy.signal import convolve2d
  3.  
  4. X = np.random.randint(5, size=(10,10))
  5. K = np.random.randint(5, size=(3,3))
  6. print 'Input:'
  7. print X[:3,:3]
  8. print 'Kernel:'
  9. print K
  10.  
  11. print 'Hardcording the calculation of a valid convolution (top-left)'
  12. print (X[:3,:3]*K)
  13. print 'Sums to'
  14. print (X[:3,:3]*K).sum()
  15. print 'However the top-left value of the convolve2d result'
  16. Y = convolve2d(X, K, 'valid')
  17. print Y[0,0]
  18.  
  19. Input:
  20. [[4 1 4]
  21. [3 3 3]
  22. [3 4 0]]
  23. Kernel:
  24. [[1 3 0]
  25. [0 2 2]
  26. [2 1 3]]
  27. Hardcording the calculation of a valid convolution (top-left)
  28. [[4 3 0]
  29. [0 6 6]
  30. [6 4 0]]
  31. Sums to
  32. 29
  33. However the top-left value of the result
  34. 45
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement