""" Exercise 5.3 from "A primer on..." Fill two arrays with values, this time using vecorized operations and avoiding the for-loop. """ import numpy as np def h(x): return (1 / np.sqrt(2 * np.pi)) * np.exp(-0.5 * x**2) a = -4 b = 4 n = 41 x = np.linspace(a, b, n) y = h(x) print(x) print(y) """ Terminal> python fill_arrays_vectorized.py [-4. -3.8 -3.6 -3.4 -3.2 -3. -2.8 -2.6 -2.4 -2.2 -2. -1.8 -1.6 -1.4 -1.2 -1. -0.8 -0.6 -0.4 -0.2 0. 0.2 0.4 0.6 0.8 1. 1.2 1.4 1.6 1.8 2. 2.2 2.4 2.6 2.8 3. 3.2 3.4 3.6 3.8 4. ] [1.33830226e-04 2.91946926e-04 6.11901930e-04 1.23221917e-03 2.38408820e-03 4.43184841e-03 7.91545158e-03 1.35829692e-02 2.23945303e-02 3.54745928e-02 5.39909665e-02 7.89501583e-02 1.10920835e-01 1.49727466e-01 1.94186055e-01 2.41970725e-01 2.89691553e-01 3.33224603e-01 3.68270140e-01 3.91042694e-01 3.98942280e-01 3.91042694e-01 3.68270140e-01 3.33224603e-01 2.89691553e-01 2.41970725e-01 1.94186055e-01 1.49727466e-01 1.10920835e-01 7.89501583e-02 5.39909665e-02 3.54745928e-02 2.23945303e-02 1.35829692e-02 7.91545158e-03 4.43184841e-03 2.38408820e-03 1.23221917e-03 6.11901930e-04 2.91946926e-04 1.33830226e-04] """