title: How to obtain a gaussian filter in python
body: <p>I am using python to create a gaussian filter of size 5x5.
  I saw this post <a href="https://stackoverflow.com/questions/11209115/creating-gaussian-filter-of-required-length-in-python">here</a> where they talk about a similar thing but I didn't find the exact way to get equivalent python code to matlab function <code>fspecial('gaussian', f_wid, sigma)</code>
  Is there any other way to do it? 
  I tried using the following code :</p>
  
  <pre><code>size = 2
  sizey = None
  size = int(size)
  if not sizey:
      sizey = size
  else:
      sizey = int(sizey)
  x, y = scipy.mgrid[-size: size + 1, -sizey: sizey + 1]
  g = scipy.exp(- (x ** 2/float(size) + y ** 2 / float(sizey)))
  print g / np.sqrt(2 * np.pi)
  </code></pre>
  
  <p>The output obtained is </p>
  
  <pre><code>[[ 0.00730688  0.03274718  0.05399097  0.03274718  0.00730688]
   [ 0.03274718  0.14676266  0.24197072  0.14676266  0.03274718]
   [ 0.05399097  0.24197072  0.39894228  0.24197072  0.05399097]
   [ 0.03274718  0.14676266  0.24197072  0.14676266  0.03274718]
   [ 0.00730688  0.03274718  0.05399097  0.03274718  0.00730688]]
  </code></pre>
  
  <p>What I want is something like this:</p>
  
  <pre><code>   0.0029690   0.0133062   0.0219382   0.0133062   0.0029690
     0.0133062   0.0596343   0.0983203   0.0596343   0.0133062
     0.0219382   0.0983203   0.1621028   0.0983203   0.0219382
     0.0133062   0.0596343   0.0983203   0.0596343   0.0133062
     0.0029690   0.0133062   0.0219382   0.0133062   0.0029690
  </code></pre>