scipy.special
) scipy.integrate
) scipy.optimize
) scipy.interpolate
)scipy.fftpack
) scipy.signal
)scipy.linalg
)scipy.sparse.csgraph
)scipy.stats
)scipy.ndimage
) scipy.io
)scipy.weave
)scipy.integrate
¶Integrate the function:
$$ f(x) = \int_{0}^4 x^2 {\rm d}x $$import scipy.integrate
ans, err = scipy.integrate.quad(lambda x: x ** 2, 0., 4)
ans
21.333333333333336
See also: dblquad
, tplquad
, fixed_quad
, trapz
, simps
import numpy as np
import scipy.linalg
a = np.random.rand(3,3)
scipy.linalg.inv(a)
array([[ 2.09386567, 0.18794291, -2.33891785], [ 4.50278126, -2.39788758, -1.04738682], [-6.0432121 , 2.88320448, 3.46459537]])
scipy.linalg.eigvals(a)
array([ 2.08083995+0.j, 0.16847753+0.j, -0.30717139+0.j])
scipy.interpolate
¶import numpy as np
from scipy import interpolate, integrate
x = np.arange(-1,11)
y = np.exp(-x/3.0)
f = interpolate.interp1d(x,y); f
<scipy.interpolate.interpolate.interp1d at 0x1127a2728>
ans, err = integrate.quad(f,0,10); ans
2.9197153790964223
integrate.simps(y[1:-1],x[1:-1])
2.8550038226912573
A free alternative to MATLAB
The power of the full Python language