SciPy

SciPy is an open source library of high-quality scientific tools for the Python programming language. It must not be confused with the concurrent project Scientific Python.

SciPy uses the array handling of the NumPy or/and Numarray modules. Furthermore, it contains modules for graphics and plotting, optimization, integration, special functions, signal and image processing, genetic algorithms, ODE solvers, and others.

SciPy is targeted towards similar applications as MATLAB and Scilab.

SciPy is currently distributed under the BSD license and its developement is sponsored by Enthought.

Contents

Data structures

The basic data structure in SciPy is the array. The SciPy project is slowly moving from the original NumPy Numeric array type to the newer Numarray implementation.

Modules

Overview

Available subpackages:

  • plt, gplt, xplt: graphics
  • special: Special Functions
  • linalg: Linear algebra routines
    • sparse: Sparse matrix
    • cluster: Vector Quantization / Kmeans
  • fftpack: Discrete Fourier Transform algorithms
  • optimize: Optimization Tools
  • interpolate: Interpolation Tools
  • integrate: Integration routines
  • ga: Genetic Algorithms
  • stats: Statistical Functions
  • cow: Cluster Of Workstations
  • signal: Signal Processing Tools
  • io: Data input and output

Graphics

Currently, SciPy has three graphics packages:

  • scipy.plt, a cross-platform package written from scratch,
  • scipy.gplt, a front-end to the cross-platform plotting tool Gnuplot, and
  • scipy.xplt, based on Gist, therefore limited to systems running X11.

Ultimately, their functionalities shall be merged in scipy.plt. As of November 2004, scipy.plt is still missing advanced graphics capabilities such as 3-d-plotting.

The following sample shows a SciPy session with a simple plot:

>>> import gui_thread
>>> gui_thread.start()
>>> from scipy import plt
>>> plt.plot((1,2,3))

If SciPy is used from a wxPython shell such as Boa constructor or PyCrust, the above sample simplifies to

>>> from scipy import plt
>>> plt.plot((1,2,3))

Image processing capabilities are available through the Python Imaging Library (PIL).

Complex example

The following code demonstrates several capabilities of SciPy: the one-dimensional motion of an object in the Earth's gravity field is calculated by integrating Newton's equation of motion, then fitted by a parabola:


## Initializations:
print "initializing ..."
import gui_thread
gui_thread.start()
from scipy import plt
from numarray import arange
from scipy.integrate import odeint
from scipy.optimize import leastsq
print "running ..."
## Simulate 1-dimensional Newtonian dynamics:
# set times for which we want data (these are NOT the integration steps):
T=arange(0,4.,.01) 
# given acceleration as function of position, velocity or/and time:
def acc(s,v,t):
    return -9.81
# set initial position and velocity:
sv0=[0,10]
# first derivative of [s,v] will be equated with fu:
def fu(sv,t):
	return[sv[1],acc(sv[0],sv[1],t)]
# integrate equation of motion:
SV = odeint(fu,sv0,T)
S=SV[:,0] # obtain s(t) as a slice of sv(t)
## Fit resulting s(t):
# model function (a parabola):
def model(p,t):
    return p[0]+p[1]*t+p[2]*t*t
# initial values for fit parameters:
p0=[.1,.6,4.]
# perform the fit:
def residue(param,datum,t):
    return datum - model(param,t)
fit=leastsq(residue,p0,args=(S,T))
p=fit[0] # final fit parameters
# print and plot results:
print "fit result: ", p
Sfit = model(p,T) # fitted parabola
plt.plot(T,S,'bx',T,Sfit,'m-')

External links

Navigation

  • Art and Cultures
    • Art (https://academickids.com/encyclopedia/index.php/Art)
    • Architecture (https://academickids.com/encyclopedia/index.php/Architecture)
    • Cultures (https://www.academickids.com/encyclopedia/index.php/Cultures)
    • Music (https://www.academickids.com/encyclopedia/index.php/Music)
    • Musical Instruments (http://academickids.com/encyclopedia/index.php/List_of_musical_instruments)
  • Biographies (http://www.academickids.com/encyclopedia/index.php/Biographies)
  • Clipart (http://www.academickids.com/encyclopedia/index.php/Clipart)
  • Geography (http://www.academickids.com/encyclopedia/index.php/Geography)
    • Countries of the World (http://www.academickids.com/encyclopedia/index.php/Countries)
    • Maps (http://www.academickids.com/encyclopedia/index.php/Maps)
    • Flags (http://www.academickids.com/encyclopedia/index.php/Flags)
    • Continents (http://www.academickids.com/encyclopedia/index.php/Continents)
  • History (http://www.academickids.com/encyclopedia/index.php/History)
    • Ancient Civilizations (http://www.academickids.com/encyclopedia/index.php/Ancient_Civilizations)
    • Industrial Revolution (http://www.academickids.com/encyclopedia/index.php/Industrial_Revolution)
    • Middle Ages (http://www.academickids.com/encyclopedia/index.php/Middle_Ages)
    • Prehistory (http://www.academickids.com/encyclopedia/index.php/Prehistory)
    • Renaissance (http://www.academickids.com/encyclopedia/index.php/Renaissance)
    • Timelines (http://www.academickids.com/encyclopedia/index.php/Timelines)
    • United States (http://www.academickids.com/encyclopedia/index.php/United_States)
    • Wars (http://www.academickids.com/encyclopedia/index.php/Wars)
    • World History (http://www.academickids.com/encyclopedia/index.php/History_of_the_world)
  • Human Body (http://www.academickids.com/encyclopedia/index.php/Human_Body)
  • Mathematics (http://www.academickids.com/encyclopedia/index.php/Mathematics)
  • Reference (http://www.academickids.com/encyclopedia/index.php/Reference)
  • Science (http://www.academickids.com/encyclopedia/index.php/Science)
    • Animals (http://www.academickids.com/encyclopedia/index.php/Animals)
    • Aviation (http://www.academickids.com/encyclopedia/index.php/Aviation)
    • Dinosaurs (http://www.academickids.com/encyclopedia/index.php/Dinosaurs)
    • Earth (http://www.academickids.com/encyclopedia/index.php/Earth)
    • Inventions (http://www.academickids.com/encyclopedia/index.php/Inventions)
    • Physical Science (http://www.academickids.com/encyclopedia/index.php/Physical_Science)
    • Plants (http://www.academickids.com/encyclopedia/index.php/Plants)
    • Scientists (http://www.academickids.com/encyclopedia/index.php/Scientists)
  • Social Studies (http://www.academickids.com/encyclopedia/index.php/Social_Studies)
    • Anthropology (http://www.academickids.com/encyclopedia/index.php/Anthropology)
    • Economics (http://www.academickids.com/encyclopedia/index.php/Economics)
    • Government (http://www.academickids.com/encyclopedia/index.php/Government)
    • Religion (http://www.academickids.com/encyclopedia/index.php/Religion)
    • Holidays (http://www.academickids.com/encyclopedia/index.php/Holidays)
  • Space and Astronomy
    • Solar System (http://www.academickids.com/encyclopedia/index.php/Solar_System)
    • Planets (http://www.academickids.com/encyclopedia/index.php/Planets)
  • Sports (http://www.academickids.com/encyclopedia/index.php/Sports)
  • Timelines (http://www.academickids.com/encyclopedia/index.php/Timelines)
  • Weather (http://www.academickids.com/encyclopedia/index.php/Weather)
  • US States (http://www.academickids.com/encyclopedia/index.php/US_States)

Information

  • Home Page (http://academickids.com/encyclopedia/index.php)
  • Contact Us (http://www.academickids.com/encyclopedia/index.php/Contactus)

  • Clip Art (http://classroomclipart.com)
Toolbox
Personal tools