""" Exercise 5.2 from "A primer on..." Fill two arrays with values, using a similar recipe as for lists. Since arrays have fixed length, we initialize arrays with the correct size and all values zero. Then we fill in the values using a for-loop and indexing. """ import numpy as np def h(x): return (1 / np.sqrt(2 * np.pi)) * np.exp(-0.5 * x**2) #xlist = [] #hlist = [] a = -4 b = 4 n = 41 dx = (b - a) / (n-1) x = np.zeros(n) y = np.zeros(n) for i in range(n): x[i] = a + i * dx y[i] = h(x[i]) print(x) print(y)