from maxima import find_maxima find_maxima([1, 2, 3, 2, 4, 1]) %run test_maxima.py find_maxima([1, 2, 1, 2, 3]) find_maxima([1, 1, 1]) import numpy as np a = np.random.randn(100, 200) b = np.random.randn(100, 200) c = np.zeros_like(a) %%timeit assert a.shape == b.shape N = a.shape[0] M = a.shape[1] for i in range(N): for j in range(M): c[i, j] = a[i, j] + b[i, j] %%timeit c = a + b from IPython.display import HTML HTML('') %matplotlib inline import numpy as np from scipy import optimize import matplotlib.pyplot as plt %%prun -s cumtime def kepler(E, e, M): """Kepler's equation.""" return E - e * np.sin(E) - M fig, axes = plt.subplots(figsize=(6, 6)) N = 10000 M_domain = np.linspace(0, 2 * np.pi, N) for ecc in 0.0167, 0.249, 0.432, 0.775, 0.967: E_domain = np.zeros_like(M_domain) ii = 0 for M in M_domain: sol = optimize.root(kepler, E_domain[ii], args=(ecc, M)) E_domain[ii] = sol.x ii += 1 axes.plot(M_domain, E_domain) axes.set_xlim(0, 2 * np.pi) axes.set_ylim(0, 2 * np.pi) axes.set_xlabel("\$M\$", fontsize=15) axes.set_ylabel("\$E\$", fontsize=15) axes.set_aspect(1) axes.grid(True) axes.legend(["Earth", "Pluto", "Comet Holmes", "28P/Neujmin", "Halley's Comet"], loc=2) axes.set_title("Kepler's equation solutions")