# Gaussian filter Kernels for various linear filters. (a) Mean with uniform weights and square support. (b) Mean with uniform weights and circular support. (c) Mean with triangular weights and circular support; the mean is computed with n = 25, the total of the weight factors. (d) A discrete approximation to a Gaussian with σ = 1, for which the mean is computed with n = 273.

There are many other linear smoothing filters, but the most important one is the Gaussian filter, which applies weights according to the Gaussian distribution (d in the figure).

The key parameter is σ, which controls the extent of the kernel and consequently the degree of smoothing (and how long the algorithm takes to execute). More aggressive than the mean filter, the Gaussian filter deals with random noise more effectively (Figures 1d and 2d). But it still simply mixes the noise into the result and smooths indiscriminately across edges. Again, it is imperative to remove spikes before applying this filter.

## Optimizing

It's important that the Gaussian kernel is not too small — it must be large enough to 'fade out' without sharp edges. Edges have large bandwidth, so they introduce aliasing artifacts into the result after convolution.

The optimal value for σ is between about 0.8 and 1.0.

## Implementation in Python

We can make a Gaussian kernel in Python:

```def gaussian_kernel(size, size_y=None):
size = int(size)
if not size_y:
size_y = size
else:
size_y = int(size_y)
x, y = numpy.mgrid[-size:size+1, -size_y:size_y+1]
g = numpy.exp(-(x**2/float(size)+y**2/float(size_y)))
return g / g.sum()

# Make the Gaussian by calling the function
gaussian_kernel_array = gaussian_kernel(5)

plt.imshow(gaussian_kernel_array, cmap=plt.get_cmap('jet'), interpolation='nearest')
plt.colorbar()
plt.show()```

But we don't really need to — we can just use the SciPy signal processing library:

```import scipy.ndimage
gaussian = scipy.ndimage.filters.gaussian_filter(noisy_horizon, 3.0)

plt.imshow(gaussian, aspect=0.5, vmin=vmin, vmax=vmax)
plt.show()```