Professional Documents
Culture Documents
SciPy 1
SciPy 1
Scipy
SciPy
• SciPy is an Open Source library of scientific tools for Python. It depends on the NumPy
library, and it gathers a variety of high level science and engineering modules together
as a single package. SciPy provides modules for
– file input/output
– statistics
– optimization
– numerical integration
– linear algebra
– Fourier transforms
– signal processing
– image processing
– ODE solvers
– special functions
– and more...
• See http://docs.scipy.org/doc/scipy/reference/tutorial/
SciPy: Statistics
scipy.stats
>>> from scipy import stats
>>> dir(stats)
>>> I = sqrt(2/pi)*(18.0/27*sqrt(2)*cos(4.5)-4.0/27*sqrt(2)*sin(4.5)+ :
... sqrt(2*pi)*special.fresnel(3/sqrt(pi))[0])
>>> print I
1.11781793809
scipy.linalg
SciPy is built using the optimized ATLAS LAPACK (Linear Algebra PACKage)
and BLAS (Basic Linear Algebra Subprograms) libraries, it has very fast linear
algebra capabilities. All of these linear algebra routines expect an object that
can be converted into a 2-dimensional array. The matrix class is initialized with
the SciPy command mat which is just convenient short-hand for matrix.
>>> A = matrix('1.0 2.0; 3.0 4.0')
>>> A
[[ 1. 2.]
[ 3. 4.]]
Finding Determinant
Minimize
c1,c2= 5.0,2.0
i = r_[1:11]
xi = 0.1*i
yi = c1*exp(-xi)+c2*xi
zi = yi + 0.05*max(yi)*random.randn(len(yi))
A = c_[exp(-xi)[:,newaxis],xi[:,newaxis]]
c,resid,rank,sigma = linalg.lstsq(A,zi)
xi2 = r_[0.1:1.0:100j]
yi2 = c[0]*exp(-xi2) + c[1]*xi2
plt.plot(xi,zi,'x',xi2,yi2)
plt.axis([0,1.1,3.0,5.5])
plt.xlabel('$x_i$')
plt.title('Data fitting with linalg.lstsq')
plt.show()
SciPy – Singular value decomposition
Singular Value Decompostion (SVD) can be thought of as an extension of the
eigenvalue problem to matrices that are not square. Let A be an M x N matrix.
SVD of A can be written as
With U = AHA and V= AAH and is the matrix of eigenvectors
Simple differential equations can be solved numerically using the Euler-Cromer method, but more
complicated differential equations may require a more sophisticated method. The scipy library for Python
contains numerous functions for scientific computing and data analysis. It includes the function odeint for
numerically
from solving sets
scipy import of first-order, ordinary differential equations (ODEs) using a sophisticated algorithm.
odeint
from pylab import * # for plotting commands
End