Skip to main content Accessibility help
×
Hostname: page-component-848d4c4894-xm8r8 Total loading time: 0 Render date: 2024-07-03T13:27:27.863Z Has data issue: false hasContentIssue false

8 - SciPy

Published online by Cambridge University Press:  05 February 2016

Christian Hill
Affiliation:
University College London
Get access

Summary

SciPy is a library of Python modules for scientific computing that provides more specific functionality than the generic data structures and mathematical algorithms of NumPy. For example, it contains modules for the evaluation of special functions frequently encountered in science and engineering, optimization, integration, interpolation and image manipulation. As with the NumPy library, many of SciPy's underlying algorithms are executed as compiled C code, so they are fast. Also like NumPy and Python itself, SciPy is free software.

There is little new syntax to learn in using the SciPy routines, so this chapter will focus on examples of the library's use in short programs of relevance to science and engineering.

Physical constants and special functions

The useful scipy.constants package provides the internationally agreed standard values and uncertainties for physical constants. The scipy.special package also supplies a large number of algorithms for calculating functions that appear in science, mathematical analysis and engineering, including:

• Airy functions

• Elliptic functions and integrals

• Bessel functions, their zeros, derivatives and integrals

• Spherical Bessel functions

• Struve functions

• A variety of statistical functions and distributions

• Gamma and beta functions

• The error function

• Fresnel integrals

• Legendre functions and associated Legendre functions

• A variety of orthogonal polynomials

• Hypergeometric functions

• Parabolic cylinder functions

• Matheiu functions

• Spheroidal functions

• Kelvin functions

They are described in detail in the documentation; we focus in this section on a few representative examples.

Most of these special functions are implemented in SciPy as universal functions: that is, they support broadcasting and vectorization (automatic array-looping), and so work as expected with NumPy arrays.

Physical constants

SciPy contains the 2010 CODATA internationally recommended values of many physical constants. They are held, with their units and uncertainties, in a dictionary, scipy.constants.physical_constants, keyed by an identifying string. For example,

In [x]: import scipy.constants as pc

In [x]: pc.physical_constants[’Avogadro constant’]

Out[x]: (6.02214129e+23, ‘mol^-1’, 2.7e+16)

The convenience methods value, unit and precision retrieve the corresponding properties on their own:

In [x]: pc.value(‘elementary charge’)

Out[x]: 1.602176565e-19

In [x]: pc.unit(’elementary charge’)

Out[x]: ‘C’

In [x]: pc.precision(’elementary charge’)

2.1845282701410628e-08

To save typing, it is usual to assign the value to a variable name at the start of a program, for example, …

Type
Chapter
Information
Publisher: Cambridge University Press
Print publication year: 2016

Access options

Get access to the full version of this content by using one of the access options below. (Log in options will check for institutional or personal access. Content may require purchase if you do not have access.)

Save book to Kindle

To save this book to your Kindle, first ensure coreplatform@cambridge.org is added to your Approved Personal Document E-mail List under your Personal Document Settings on the Manage Your Content and Devices page of your Amazon account. Then enter the ‘name’ part of your Kindle email address below. Find out more about saving to your Kindle.

Note you can select to save to either the @free.kindle.com or @kindle.com variations. ‘@free.kindle.com’ emails are free but can only be saved to your device when it is connected to wi-fi. ‘@kindle.com’ emails can be delivered even when you are not connected to wi-fi, but note that service fees apply.

Find out more about the Kindle Personal Document Service.

  • SciPy
  • Christian Hill, University College London
  • Book: Learning Scientific Programming with Python
  • Online publication: 05 February 2016
  • Chapter DOI: https://doi.org/10.1017/CBO9781139871754.008
Available formats
×

Save book to Dropbox

To save content items to your account, please confirm that you agree to abide by our usage policies. If this is the first time you use this feature, you will be asked to authorise Cambridge Core to connect with your account. Find out more about saving content to Dropbox.

  • SciPy
  • Christian Hill, University College London
  • Book: Learning Scientific Programming with Python
  • Online publication: 05 February 2016
  • Chapter DOI: https://doi.org/10.1017/CBO9781139871754.008
Available formats
×

Save book to Google Drive

To save content items to your account, please confirm that you agree to abide by our usage policies. If this is the first time you use this feature, you will be asked to authorise Cambridge Core to connect with your account. Find out more about saving content to Google Drive.

  • SciPy
  • Christian Hill, University College London
  • Book: Learning Scientific Programming with Python
  • Online publication: 05 February 2016
  • Chapter DOI: https://doi.org/10.1017/CBO9781139871754.008
Available formats
×