title: Simpliest way to generate a 1D gaussian kernel
body: <p>I'm wondering what would be the easiest way to generate a 1D gaussian kernel in python given the filter length. I think that the idea is to evaluate the normal distribution for the values of the vector [-filter-length,...,filter_length], is it correct?</p>
  
  <p>So far, I've done this, but I don't know why it is not correct:</p>
  
  <pre><code>result = np.zeros( filter_length )
  
  mid = filter_length/2
  result=[(1/(sigma*np.sqrt(2*np.pi)))*(1/(numpy.exp((i**2)/(2*sigma**2)))) for i in range(-mid,mid+1)]  
  
  return result
  </code></pre>
  
  <p>where <code>sigma</code> is the standard deviation, which is a parameter. <code>filter-length</code> is also a parameter.</p>
  
  <p>It's incorrect because I get, for example, for length=3 and <strong>sigma=math.sqrt(1.0/2/math.log(2))</strong></p>
  
  <p>[0.23485931967491286, 0.46971863934982572, 0.23485931967491286]</p>
  
  <p>And it should be:</p>
  
  <p>[0.25, 0.5, 0.25]</p>
  
  <p>So, is there any problem of rounding? I don't know what is going on...</p>
  
  <p><strong>Edit</strong> I think that I should truncate somehow</p>
  
  <p><strong>Problem Solved</strong> The problem was that I wasn't normalizing. I had to divide the vector by the sum of all its components.</p>