scipy

What it is good for?

Scientific calculations.

scipy is a Python library for fitting functions and other kinds of numerical
analyses. You find functions for signal processing, Fourier Transform, generating random datasets and many more. Scipy uses numpy and matplotlib.

Installed with Python by default

no

Installed with Anaconda

yes

How to install it?

  1. pip install scipy

Example

Define a square function; create noisy X/Y data using numpy:

  1. def func(x, a, b):
  2. return a * x**2 + b
  3. import numpy as np
  4. x = np.linspace(-10, 10, 100)
  5. y = func(x, 1, 5)
  6. ynoise = y + 20 * np.random.laplace(size=len(x))

Fit the parameters of the function with noisy data:

  1. from scipy.optimize import curve_fit
  2. params, pcov = curve_fit(func, x , ynoise)
  3. yfit = func(x, params[0], params[1])

Plot the outcome:

  1. import matplotlib.pyplot as plt
  2. fig = plt.figure
  3. plt.plot(x, yfit, "k-")
  4. plt.plot(x, ynoise, "bx")
  5. plt.savefig('fit.png')

Where to learn more?

http://scipy.org/