Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
IPython Notebook Essentials

You're reading from  IPython Notebook Essentials

Product type Book
Published in Nov 2014
Publisher
ISBN-13 9781783988341
Pages 190 pages
Edition 1st Edition
Languages
Author (1):
Luiz Felipe Martins Luiz Felipe Martins
Profile icon Luiz Felipe Martins

Chapter 5. Advanced Computing with SciPy, Numba, and NumbaPro

In this chapter, the user will learn how to use SciPy to perform scientific computations. The Numba package will then be introduced as a way to accelerate computations. Finally, the NumbaPro capabilities of parallel execution in the GPU will be presented.

In this chapter, we will cover the following topics:

  • Overview of SciPy

  • Advanced mathematical algorithms with SciPy

  • Accelerating computations with Numba and NumbaPro

Before running the examples in this chapter, load pylab by running the following command in a computing cell:

%pylab inline

Overview of SciPy


SciPy is an extensive library for applied mathematics and scientific computation. The following is the complete list of all the modules available in the library:

Module

Functionality

cluster

Clustering algorithms

constants

Physical and mathematical constants

fftpack

Fast Fourier Transform

integrate

Integration and ordinary differential equations

interpolate

Interpolation and splines

io

Input and output

linalg

Linear algebra

ndimage

Image processing

odr

Orthogonal distance regression

optimize

Optimization and root-finding

signal

Signal processing

sparse

Sparse matrices

spatial

Spatial data structures

special

Special functions

stats

Statistical distributions

weave

C/C++ integration

The standard way to import SciPy modules in scripts is using the following command line:

from scipy import signal

Then, individual functions can be called with the usual module reference syntax, as follows:

signal.correlate(…)...

Advanced mathematical algorithms with SciPy


In this section, we will cover some of the algorithms available in SciPy. Each of the following subsections features a representative example from a significant area of applied science. The examples are chosen so as not to require extensive domain knowledge but still be realistic. These are the topics and examples that we present:

  • Solving equations and finding optimal values: We will study a market model that requires the solution of a nonlinear system and a facility location problem requiring a nonstandard optimization.

  • Calculus and differential equations: We will present a volume calculation that uses integral calculus, and Newton's canon, a thought experiment proposed by Isaac Newton, which we will model using a system of differential equations. Finally, we will present a three-dimensional system, the famous Lorenz equations, which is an early example displaying chaotic behavior.

Solving equations and finding optimal values

To illustrate this...

Accelerating computations with Numba and NumbaPro


In this section, we will discuss Numba and NumbaPro, two very exciting libraries to accelerate the NumPy code. Numba and NumbaPro were created by Continuum Analytics, the same company that produces the Anaconda distribution. Numba is part of the standard Anaconda distribution, but NumbaPro is a commercial product that must be purchased separately as part of the Accelerate package. However, NumbaPro can be downloaded for a free trial period.

These libraries are unique in that they allow the acceleration of code with the addition of a few lines of code. As the first example, let's consider the following lines of code to multiply two matrices:

def matrix_multiply(A, B):
    m, n = A.shape
    n, r = B.shape
    C = zeros((m, r), float64)
    for i in range(m):
        for j in range(r):
            acc = 0
            for k in range(n):
                acc += A[i, k] * B[k, j]
            C[i, j] = acc
    return C

The preceding code uses the...

Summary


In this chapter, we covered the use of advanced mathematical algorithms in SciPy, including solving equations and finding optimal values, integration, and differential equations. The chapter concluded with a discussion on using parallelization in the GPU to accelerate computations.

lock icon The rest of the chapter is locked
You have been reading a chapter from
IPython Notebook Essentials
Published in: Nov 2014 Publisher: ISBN-13: 9781783988341
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}