Python/NumPy

NumPy is the cornerstone of scientific Python ecosystem, providing the basic numerical computing capabilities.

In addition to NumPy’s official documentation, Jake VanderPlas‘s Python Data Science Handbook provides the basics and Nicolas P. Rougier‘s From Python to Numpy extensively cover NumPy.

Tips

  1. Avoid loops and vectorize as much as possible.
  2. You can avoid creating a temporary array by specifying the out parameter in NumPy functions.

For instance,

x = np.arange(5)
y = np.empty(5)
np.multiply(x, 10, out=y)
print(y)

y = np.zeros(10)
np.power(2, x, out=y[::2])
print(y)