So this recipe is a short example on how to generate a generic 2D Gaussian-like array. Let's get started.
import numpy as np
Let's pause and look at these imports. Numpy is generally helpful in data manipulation while working with arrays. It also helps in performing mathematical operation.
x, y = np.meshgrid(np.linspace(-1,1,10), np.linspace(-1,1,10)) d = np.sqrt(x*x+y*y) sigma, mu = 1.0, 0.0 g = np.exp(-( (d-mu)**2 / ( 2.0 * sigma**2 ) ) )
Let's have a loop at each step one by one. One first step, we have created two, 2D arrays, using meshgrid and linespace function. Meshgrid basically creates a rectangular grid out of two given one-dimensional array. Linespace returns number spaces evenly w.r.t interval. In 2nd step, we are calculating the square-roots of squares of s and y. Finally, using exp function, we are genearating the guassian array.
Simply using print function, we have print our gaussian array.
Once we run the above code snippet, we will see:
Scroll down to the ipython file below to visualize the output.