Q:

Write a NumPy program to generate a generic 2D Gaussian-like array

0

Write a NumPy program to generate a generic 2D Gaussian-like array

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

import numpy as np
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 ) ) )
print("2D Gaussian-like array:")
print(g)

Sample Output:

2D Gaussian-like array:                                                                
[[ 0.36787944  0.44822088  0.51979489  0.57375342  0.60279818  0.60279818              
   0.57375342  0.51979489  0.44822088  0.36787944]                                     
 [ 0.44822088  0.54610814  0.63331324  0.69905581  0.73444367  0.73444367              
   0.69905581  0.63331324  0.54610814  0.44822088]                                     
 [ 0.51979489  0.63331324  0.73444367  0.81068432  0.85172308  0.85172308              
   0.81068432  0.73444367  0.63331324  0.51979489]                                     
 [ 0.57375342  0.69905581  0.81068432  0.89483932  0.9401382   0.9401382               
   0.89483932  0.81068432  0.69905581  0.57375342]                                     
 [ 0.60279818  0.73444367  0.85172308  0.9401382   0.98773022  0.98773022              
   0.9401382   0.85172308  0.73444367  0.60279818]                                     
 [ 0.60279818  0.73444367  0.85172308  0.9401382   0.98773022  0.98773022              
   0.9401382   0.85172308  0.73444367  0.60279818]                                     
 [ 0.57375342  0.69905581  0.81068432  0.89483932  0.9401382   0.9401382               
   0.89483932  0.81068432  0.69905581  0.57375342]                                     
 [ 0.51979489  0.63331324  0.73444367  0.81068432  0.85172308  0.85172308              
   0.81068432  0.73444367  0.63331324  0.51979489]                                     
 [ 0.44822088  0.54610814  0.63331324  0.69905581  0.73444367  0.73444367              
   0.69905581  0.63331324  0.54610814  0.44822088]                  
[ 0.36787944  0.44822088  0.51979489  0.57375342  0.60279818  0.60279818              
   0.57375342  0.51979489  0.44822088  0.36787944]]

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now