Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Mastering SciPy
Mastering SciPy

Mastering SciPy: Implement state-of-the-art techniques to visualize solutions to challenging problems in scientific computing, with the use of the SciPy stack

Arrow left icon
Profile Icon Francisco Javier B Silva Profile Icon Blanco-Silva
Arrow right icon
$19.99 per month
Full star icon Full star icon Full star icon Half star icon Empty star icon 3.5 (2 Ratings)
Paperback Nov 2015 404 pages 1st Edition
eBook
$27.99 $40.99
Paperback
$49.99
Subscription
Free Trial
Renews at $19.99p/m
Arrow left icon
Profile Icon Francisco Javier B Silva Profile Icon Blanco-Silva
Arrow right icon
$19.99 per month
Full star icon Full star icon Full star icon Half star icon Empty star icon 3.5 (2 Ratings)
Paperback Nov 2015 404 pages 1st Edition
eBook
$27.99 $40.99
Paperback
$49.99
Subscription
Free Trial
Renews at $19.99p/m
eBook
$27.99 $40.99
Paperback
$49.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
Table of content icon View table of contents Preview book icon Preview Book

Mastering SciPy

Chapter 2. Interpolation and Approximation

Approximation theory states how to find the best approximation to a given function by another function from some predetermined class and how good this approximation is. In this chapter, we are going to explore this field through two settings: interpolation and least squares approximation.

Motivation

Consider a meteorological experiment that measures the temperature of a set of buoys located on a rectangular grid at sea. We can emulate such an experiment by indicating the longitude and latitude of the buoys on a grid of 16 × 16 locations, and random temperatures on them between say 36ºF and 46ºF:

In [1]: import numpy as np, matplotlib.pyplot as plt, \
   ...: matplotlib.cm as cm; \
   ...: from mpl_toolkits.basemap import Basemap
In [2]: map1 = Basemap(projection='ortho', lat_0=20, lon_0=-60, \
   ...:                resolution='l', area_thresh=1000.0); \
   ...: map2 = Basemap(projection='merc', lat_0=20, lon_0=-60, \
   ...:                resolution='l', area_thresh=1000.0, \
   ...:                llcrnrlat=0,  urcrnrlat=45, \
   ...:                llcrnrlon=-75, urcrnrlon=-15)
In [3]: longitudes = np.linspace(-60, -30, 16); \
   ...: latitudes = np.linspace(15, 30, 16); \
   ...: lons, lats = np.meshgrid(longitudes...

Interpolation

We have three different implementation methodologies to deal with interpolation problems:

  • A procedural mode that computes a set of data points (in the form of ndarray with the required dimension) representing the actual solution.
  • In a few special cases, a functional mode that provides us with numpy functions representing the solutions.
  • An object-oriented mode that creates classes for interpolation problems. Different classes have different methods, depending on the operations that the particular kinds of interpolants enjoy. The advantage of this mode is that, through these methods, we can request more information from the solutions: not only evaluation or representation, but also relevant operations like searching for roots, computing derivatives and antiderivatives, error checking, and calculating coefficients and knots.

The choice of mode to represent our interpolants is up to us, depending mostly on how much accuracy we require, and the information/operations that we need afterwards...

Least squares approximation

Numerically, it is relatively simple to state the approximation problem for the least squares norm. This is the topic of this section.

Linear least squares approximation

In the context of linear least squares approximation, it is always possible to reduce the problem to solving a system of linear equations, as the following example shows:

Consider the sine function f(x) = sin(x) in the interval from 0 to 1. We choose as approximants the polynomials of second degree: {a0 + a1x + a2x2}. To compute the values [a0, a1, a2] that minimize this problem, we first form a 3 × 3 matrix containing the pairwise dot products (the integral of the product of two functions) of the basic functions {1, x, x2} in the given interval. Because of the nature of this problem, we obtain a Hilbert matrix of order 3:

[   < 1, 1 >    < 1, x >    < 1, x^2 > ]     [  1   1/2  1/3 ]
[   < x, 1 >    < x, x >    < x, x^2 > ]  =  [ 1/2  1/3  1/4 ]
[ < x...

Summary

In this chapter, we have explored two basic problems in the field of approximation theory: interpolation and approximation in the sense of least squares. We learned that there are three different modes to approach solutions to these problems in SciPy:

  • A procedural mode, that offers quick numerical solutions in the form of ndarrays.
  • A functional mode that offers numpy functions as the output.
  • An object-oriented mode, with great flexibility through different classes and their methods. We use this mode when we require from our solutions extra information (such as information about roots, coefficients, knots, and errors), or related objects (such as the representation of derivatives or antiderivatives).

We explored in detail all the different implementations for the interpolation coded in the scipy.interpolate module, and learned in particular that those related to splines are wrappers of several routines in the Fortran library FITPACK.

In the case of linear approximations in the least squares...

Left arrow icon Right arrow icon

Description

The SciPy stack is a collection of open source libraries of the powerful scripting language Python, together with its interactive shells. This environment offers a cutting-edge platform for numerical computation, programming, visualization and publishing, and is used by some of the world’s leading mathematicians, scientists, and engineers. It works on any operating system that supports Python and is very easy to install, and completely free of charge! It can effectively transform into a data-processing and system-prototyping environment, directly rivalling MATLAB and Octave. This book goes beyond a mere description of the different built-in functions coded in the libraries from the SciPy stack. It presents you with a solid mathematical and computational background to help you identify the right tools for each problem in scientific computing and visualization. You will gain an insight into the best practices with numerical methods depending on the amount or type of data, properties of the mathematical tools employed, or computer architecture, among other factors. The book kicks off with a concise exploration of the basics of numerical linear algebra and graph theory for the treatment of problems that handle large data sets or matrices. In the subsequent chapters, you will delve into the depths of algorithms in symbolic algebra and numerical analysis to address modeling/simulation of various real-world problems with functions (through interpolation, approximation, or creation of systems of differential equations), and extract their representing features (zeros, extrema, integration or differentiation). Lastly, you will move on to advanced concepts of data analysis, image/signal processing, and computational geometry.

Who is this book for?

If you are a professional with a proficiency in Python and familiarity with IPython, this book is for you. Some basic knowledge of numerical methods in scientific computing would be helpful.

What you will learn

  • Master relevant algorithms used in symbolic or numerical mathematics to address the approximation, interpolation, and optimization of scalar or multivariate functions
  • Develop different algorithms and strategies to effectively store and manipulate large matrices of data, with a view to solving various problems in numerical linear algebra
  • Understand how to model physical problems with systems of differential equations and distinguish the factors that dictate the strategies to solve them numerically
  • Perform statistical analysis, inference, data mining, and machine learning at higher level, and apply these to realworld problems
  • Adapt valuable ideas in computational geometry like Delaunay triangulations, Voronoi diagrams, geometric query problems, or Bezier curves, and apply them to various engineering problems
  • Familiarize yourself with different methods to represent and compress images, as well as techniques used in image processing, including edition, restoration, inpainting, segmentation, or feature recognition

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Nov 10, 2015
Length: 404 pages
Edition : 1st
Language : English
ISBN-13 : 9781783984749
Category :
Languages :
Tools :

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

Product Details

Publication date : Nov 10, 2015
Length: 404 pages
Edition : 1st
Language : English
ISBN-13 : 9781783984749
Category :
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total $ 126.97
Learning SciPy for Numerical and Scientific Computing Second Edition
$32.99
Mastering SciPy
$49.99
Mastering Matplotlib
$43.99
Total $ 126.97 Stars icon

Table of Contents

10 Chapters
1. Numerical Linear Algebra Chevron down icon Chevron up icon
2. Interpolation and Approximation Chevron down icon Chevron up icon
3. Differentiation and Integration Chevron down icon Chevron up icon
4. Nonlinear Equations and Optimization Chevron down icon Chevron up icon
5. Initial Value Problems for Ordinary Differential Equations Chevron down icon Chevron up icon
6. Computational Geometry Chevron down icon Chevron up icon
7. Descriptive Statistics Chevron down icon Chevron up icon
8. Inference and Data Analysis Chevron down icon Chevron up icon
9. Mathematical Imaging Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Half star icon Empty star icon 3.5
(2 Ratings)
5 star 50%
4 star 0%
3 star 0%
2 star 50%
1 star 0%
Raiyan Kamal Dec 29, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I'm one of the technical reviewers of this book. The book is written for readers who are already familiar with Python and some basic knowledge on various numerical methods. This book will help you a great deal to familiarize with the various Python modules for well known scientific computing use cases.Many important topics of scientific computing are covered, including:- Differential Equations- Optimization- Computational Geometry- Image processingEach chapter takes the reader through steps working on an example problem with gradually increasing complexity. Frequent code snippets from IPython notebook and matplotlib charts make the examples easy to follow. Diagrams, textual and image output is also shown whenever necessary.I'm happy to have reviewed this book and I'm very well pleased with the result. I believe this book would prove to be useful for anyone interested in harnessing the power of SciPy stack for their scientific or engineering profession or graduate level research.
Amazon Verified review Amazon
William J. Brown Nov 23, 2021
Full star icon Full star icon Empty star icon Empty star icon Empty star icon 2
There is much that can be learned from the book, but it was written in 2015 and the code hasn't been updated for python3, so much of it is unusable at this point. Also, so much math is required to exercise SciPy that it's difficult write a book that shows off the library without wandering down a very large number of paths into arcane algorithms each with a limited audience.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.