SciPy

SciPy provides a large number of functions that operate on numpy arrays and are useful for different types of scientific and engineering applications such as:

  1. Custering.
  2. Discrete Fourier Analysis.
  3. Interpolation.
  4. Linear algebra.
  5. Signal and Image processing.
  6. Optimization.
  7. Sparse matrix and sparse linear algebra.

Table of Contents

Optimization example


In [9]:
try:
    import scipy
except:
    !pip3 install scipy

try:
    import numpy as np
except:
    !pip3 install numpy
    import numpy as np
    
try:
    import matplotlib.pyplot as plt
except:
    !pip3 install matplotlib
    import matplotlib.pyplot as plt

# http://www.scipy-lectures.org/advanced/mathematical_optimization/
from scipy import optimize

In [6]:
def f(x):
    return -np.exp(-(x - .7)**2)

In [7]:
sol = optimize.brent(f)
print('min =', sol, '\nx =', f(sol))


min = 0.6999999997839409 
x = -1.0

In [10]:
x = np.arange(-10, 10, 0.1)
plt.plot(x, f(x))
plt.plot([sol],[f(sol)], 'ro')
plt.show()