Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
IPython Interactive Computing and Visualization Cookbook
IPython Interactive Computing and Visualization Cookbook

IPython Interactive Computing and Visualization Cookbook: Harness IPython for powerful scientific computing and Python data visualization with this collection of more than 100 practical data science recipes

Arrow left icon
Profile Icon Cyrille Rossant
Arrow right icon
Free Trial
Full star icon Full star icon Full star icon Full star icon Half star icon 4.5 (13 Ratings)
Paperback Sep 2014 512 pages 1st Edition
eBook
₱1571.99 ₱2245.99
Paperback
₱2806.99
Subscription
Free Trial
Arrow left icon
Profile Icon Cyrille Rossant
Arrow right icon
Free Trial
Full star icon Full star icon Full star icon Full star icon Half star icon 4.5 (13 Ratings)
Paperback Sep 2014 512 pages 1st Edition
eBook
₱1571.99 ₱2245.99
Paperback
₱2806.99
Subscription
Free Trial
eBook
₱1571.99 ₱2245.99
Paperback
₱2806.99
Subscription
Free Trial

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

IPython Interactive Computing and Visualization Cookbook

Chapter 2. Best Practices in Interactive Computing

In this chapter, we will cover the following topics:

  • Choosing (or not) between Python 2 and Python 3
  • Efficient interactive computing workflows with IPython
  • Learning the basics of the distributed version control system Git
  • A typical workflow with Git branching
  • Ten tips for conducting reproducible interactive computing experiments
  • Writing high-quality Python code
  • Writing unit tests with nose
  • Debugging your code with IPython

Introduction

This is a special chapter about good practices in interactive computing. If the rest of the book is about the content, then this chapter is about the form. It describes how to work efficiently and properly with the tools this book is about. We will cover the essentials of the version control system Git before tackling reproducible computing experiments (notably with the IPython notebook).

We will also cover more general topics in software development, such as code quality, debugging, and testing. Attention to these subjects can greatly improve the quality of our end products (for example, software, research, and publications). We will only scratch the surface here, but you will find many references to learn more about these important topics.

Choosing (or not) between Python 2 and Python 3

In this first recipe, we will briefly cover a transverse and kind of a prosaic subject: Python 2 or Python 3?

Python 3 has been available since 2008, but many Python users are still stuck with Python 2. By improving many aspects of Python 2, Python 3 has broken compatibility with the previous branch. Migrating to Python 3 may therefore require a significant investment.

Even if there aren't that many compatibility-breaking changes, a program that works perfectly fine in Python 2 may not work at all in Python 3. For example, your very first Hello World Python 2 program doesn't work anymore in Python 3; print "Hello World!" raises a SyntaxError in Python 3. Indeed, print is now a function rather than a statement. You should write print("Hello World!"), which also works fine in Python 2.

Whether you start a new project or need to maintain an old Python library, the question of choosing between Python 2 and Python 3...

Efficient interactive computing workflows with IPython

There are multiple ways of using IPython for interactive computing. Some of them are better in terms of flexibility, modularity, reusability, and reproducibility. We will review and discuss them in this recipe.

Any interactive computing workflow is based on the following cycle:

  • Write some code
  • Execute it
  • Interpret the results
  • Repeat

This fundamental loop (also known as Read-Eval-Print Loop or REPL) is particularly useful when doing exploratory research on data or model simulations, or when building a complex algorithm step by step. A more classical workflow (the edit-compile-run-debug loop) would consist of writing a full-blown program, and then performing a complete analysis. This is generally more tedious. It is more common to build an algorithmic solution iteratively, by doing small-scale experiments and tweaking the parameters, and this is precisely what interactive computing is about.

Integrated Development Environments (IDEs), providing...

Learning the basics of the distributed version control system Git

Using a distributed version control system is so natural nowadays that if you are reading this book, you are probably already using one. However, if you aren't, read this recipe carefully. You should always use a version control system for your code.

Getting ready

Notable distributed version control systems include Git, Mercurial, and Bazaar. In this chapter, we chose the popular Git system. You can download the Git program and Git GUI clients from http://git-scm.com. On Windows, you can also install msysGit (http://msysgit.github.io) and TortoiseGit (https://code.google.com/p/tortoisegit/).

Note

Distributed systems tend to be more popular than centralized systems such as SVN or CVS. Distributed systems allow local (offline) changes and offer more flexible collaboration systems.

Online providers supporting Git include GitHub (https://github.com), Bitbucket (https://bitbucket.org), Google code (https://code.google.com), Gitorious...

A typical workflow with Git branching

A distributed version control system such as Git is designed for complex and nonlinear workflows typical in interactive computing and exploratory research. A central concept is branching, which we will discuss in this recipe.

Getting ready

You need to work in a local Git repository for this recipe (see the previous recipe, Learning the basics of the distributed version control system Git).

How to do it…

  1. We create a new branch named newidea:
    $ git branch newidea
    
  2. We switch to this branch:
    $ git checkout newidea
    
  3. We make changes to the code, for instance, by creating a new file:
    $ touch newfile.py
    
  4. We add this file and commit our changes:
    $ git add newfile.py
    $ git commit -m "Testing new idea."
    
  5. If we are happy with the changes, we merge the branch to the master branch (the default):
    $ git checkout master
    $ git merge newidea
    

    Otherwise, we delete the branch:

    $ git checkout master
    $ git branch -d newidea
    

Other commands of interest include:

  • git status...

Ten tips for conducting reproducible interactive computing experiments

In this recipe, we present ten tips that can help you conduct efficient and reproducible interactive computing experiments. These are more guidelines than absolute rules.

First, we will show how you can improve your productivity by minimizing the time spent doing repetitive tasks and maximizing the time spent thinking about your core work.

Second, we will demonstrate how you can achieve more reproducibility in your computing work. Notably, academic research requires experiments to be reproducible so that any result or conclusion can be verified independently by other researchers. It is not uncommon for errors or manipulations in methods to result in erroneous conclusions that can have damaging consequences. For example, in the 2010 research paper in economics Growth in a Time of Debt, by Carmen Reinhart and Kenneth Rogoff, computational errors were partly responsible for a flawed study with global ramifications for policy...

Introduction


This is a special chapter about good practices in interactive computing. If the rest of the book is about the content, then this chapter is about the form. It describes how to work efficiently and properly with the tools this book is about. We will cover the essentials of the version control system Git before tackling reproducible computing experiments (notably with the IPython notebook).

We will also cover more general topics in software development, such as code quality, debugging, and testing. Attention to these subjects can greatly improve the quality of our end products (for example, software, research, and publications). We will only scratch the surface here, but you will find many references to learn more about these important topics.

Choosing (or not) between Python 2 and Python 3


In this first recipe, we will briefly cover a transverse and kind of a prosaic subject: Python 2 or Python 3?

Python 3 has been available since 2008, but many Python users are still stuck with Python 2. By improving many aspects of Python 2, Python 3 has broken compatibility with the previous branch. Migrating to Python 3 may therefore require a significant investment.

Even if there aren't that many compatibility-breaking changes, a program that works perfectly fine in Python 2 may not work at all in Python 3. For example, your very first Hello World Python 2 program doesn't work anymore in Python 3; print "Hello World!" raises a SyntaxError in Python 3. Indeed, print is now a function rather than a statement. You should write print("Hello World!"), which also works fine in Python 2.

Whether you start a new project or need to maintain an old Python library, the question of choosing between Python 2 and Python 3 arises. Here, we give some arguments...

Efficient interactive computing workflows with IPython


There are multiple ways of using IPython for interactive computing. Some of them are better in terms of flexibility, modularity, reusability, and reproducibility. We will review and discuss them in this recipe.

Any interactive computing workflow is based on the following cycle:

  • Write some code

  • Execute it

  • Interpret the results

  • Repeat

This fundamental loop (also known as Read-Eval-Print Loop or REPL) is particularly useful when doing exploratory research on data or model simulations, or when building a complex algorithm step by step. A more classical workflow (the edit-compile-run-debug loop) would consist of writing a full-blown program, and then performing a complete analysis. This is generally more tedious. It is more common to build an algorithmic solution iteratively, by doing small-scale experiments and tweaking the parameters, and this is precisely what interactive computing is about.

Integrated Development Environments (IDEs), providing...

Left arrow icon Right arrow icon

Description

Intended to anyone interested in numerical computing and data science: students, researchers, teachers, engineers, analysts, hobbyists... Basic knowledge of Python/NumPy is recommended. Some skills in mathematics will help you understand the theory behind the computational methods.

What you will learn

  • Code better by writing highquality, readable, and welltested programs; profiling and optimizing your code, and conducting reproducible interactive computing experiments
  • Master all of the new features of the IPython notebook, including the interactive HTML/JavaScript widgets
  • Analyze data with Bayesian and frequentist statistics (Pandas, PyMC, and R), and learn from data with machine learning (scikitlearn)
  • Gain valuable insights into signals, images, and sounds with SciPy, scikitimage, and OpenCV
  • Learn how to write blazingly fast Python programs with NumPy, PyTables, ctypes, Numba, Cython, OpenMP, GPU programming (CUDA and OpenCL), parallel IPython, MPI, and many more

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Sep 25, 2014
Length: 512 pages
Edition : 1st
Language : English
ISBN-13 : 9781783284818
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 : Sep 25, 2014
Length: 512 pages
Edition : 1st
Language : English
ISBN-13 : 9781783284818
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 ₱260 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 ₱260 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 5,613.98
IPython Interactive Computing and Visualization Cookbook
₱2806.99
Python Data Analysis
₱2806.99
Total 5,613.98 Stars icon
Banner background image

Table of Contents

16 Chapters
1. A Tour of Interactive Computing with IPython Chevron down icon Chevron up icon
2. Best Practices in Interactive Computing Chevron down icon Chevron up icon
3. Mastering the Notebook Chevron down icon Chevron up icon
4. Profiling and Optimization Chevron down icon Chevron up icon
5. High-performance Computing Chevron down icon Chevron up icon
6. Advanced Visualization Chevron down icon Chevron up icon
7. Statistical Data Analysis Chevron down icon Chevron up icon
8. Machine Learning Chevron down icon Chevron up icon
9. Numerical Optimization Chevron down icon Chevron up icon
10. Signal Processing Chevron down icon Chevron up icon
11. Image and Audio Processing Chevron down icon Chevron up icon
12. Deterministic Dynamical Systems Chevron down icon Chevron up icon
13. Stochastic Dynamical Systems Chevron down icon Chevron up icon
14. Graphs, Geometry, and Geographic Information Systems Chevron down icon Chevron up icon
15. Symbolic and Numerical Mathematics Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Full star icon Half star icon 4.5
(13 Ratings)
5 star 61.5%
4 star 30.8%
3 star 7.7%
2 star 0%
1 star 0%
Filter icon Filter
Top Reviews

Filter reviews by




P. Sebastien May 28, 2017
Full star icon Full star icon Full star icon Full star icon Full star icon 5
probably my preferred book in Python. Great case studies. Rashka, Rossant= fantastic books
Amazon Verified review Amazon
C. Smith Mar 26, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This book does a great job of providing both a useful overview and introduction to python as well as demonstrating the power and advanced functionality across a broad spectrum of topics in data science, mathematic and visualization. This book includes practical examples and code. Highly recommended.
Amazon Verified review Amazon
Randy Heiland Mar 29, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This book was well worth purchasing, in my opinion. I follow the ipython-dev list and I've seen the author's name appear many times, with very useful contributions, so I felt he certainly had the credibility to write this book. Any book about a software project runs the risk of becoming out of date as the project evolves, but in this case, at least so far, it holds up very well.The book has considerable breadth, as can be seen from the online Table of Contents (although the last page of the ToC seems to be missing). Breadth isn't necessarily a positive feature for every book/reader, but I personally like it. If one wants more depth, it's probably better to use online resources anyway.I appreciate the author being so pro open source and that he provides a github repo for code related to the book. And I personally agree with his decision to recommend using Anaconda's Python distribution; it makes life much easier when installing packages from the larger Python ecosystem. He might have gone one step further and encourage readers to join the Anaconda mailing list, but hopefully they'll figure that out on their own.I'd say the target audience is probably college students - any student in need of doing some interactive computational or data science. However, I *wish* more high school students would pick up a book like this and use it. MATLAB is fine, but Python + matplotlib, etc is better in many ways.I appreciate being made aware of the author's own visualization package, vispy, and hope to play with it more in the future. However, I was a little surprised and disappointed he didn't also mention VTK (although VTK doesn't currently install using conda/Anaconda Python 3.4).I thought it was especially brave (and admirable) of the author to contribute Chapter 5 on HPC, especially for multiple operating systems, GPU libs (CUDA and OpenCL), and MPI. Fairly advanced stuff, but worth the read.I sincerely appreciate the author undertaking this book project and commend him on the selection of topics and the overall layout. A good read with good visuals. Thanks!
Amazon Verified review Amazon
Kristbjorn Helgason Mar 29, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This book is a great source for both general data science methods and advanced interactive computing in Python. In particular, the chapter about the use of IPython Notebook is one of the best and most comprehensive text on the subject that I have seen. The introduction to different plotting libraries makes a good reference when matplotlib fails to give you the desired output.The explanations are concisely written but each sub-chapter also offers an extensive list of links to more detailed reading material, if needed.If you are looking for a book with extensive information about doing data science in IPython, everything from simple data munging to complicated machine learning, this is a good choice.
Amazon Verified review Amazon
Michael Bright Feb 23, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I read a review copy, all 509 pages as this was a great read.The book has a very broad coverage of interactive computing through the use of IPython.Each chapter and sub-section finishes with a “There’s more …” section providing a large number of useful links for further study on that sections content, allowing the reader to investigate further.The book steps us through all example source code, but the example source and example data are all provided in github repositories so all experiments can be reproduced by the reader. Sufficient information is provided to reproduce the experiments on Windows, Linux or OS X.The earlier chapters introduce us to IPython, in it’s current 2.x form but also present what’s coming in the 3.0 release. It was impressive to see how IPython is evolving into a more interactive platform through the integration of Javascript capabilities - it is shown how IPython can be extended in various ways, and how widgets can be used to interact with the visualization - e.g. having a slider widget to modify an analysis and the associated plot. One example involves the implementation of a piano keyboard within IPython.Impressive stuff showing how useful IPython is becoming for data analysis and visualization.Nevertheless for an introduction to IPython the authors’ earlier book on PacktPub “Learning IPython for Interactive Computing and Data Visualization” is a recommended read.The first part of the book covers high performance interactive computing, starting with IPython, its’ notebooks, profiling and optimization of code through various libraries including Numpy, Numba, Cython and even OpenCL or pyCUDA to harness GPUs. The final chapter of this section covers plotting libraries such as prettyplotlib, seaborn, Bokeh, NetworkX, D3.js, Vispy which go beyond the capabilities of the standard matplotlib.The second part of the book enumerates how these capabilities can be applied in many domains of data science whether it be statistical data analysis, machine learning, optimization, signal processing, image and audio, deterministic and stochastic dynamic systems, graphs and geographical systems and finally symbolic mathematics.There is a very impressive range of techniques covered in the book and the examples cover a wide range of ideas from pure statistics, to frequency domain (FFT), audio, image and graph and map plotting.Whilst such a book can not go into great depth for so many subjects, tools and methods the book provides many realistic reproducible examples, in souce code, along with many references to be able to investigate further.The last chapter deals with symbolic mathematics using sympy. I was quite amazed at what I was able to do by just installing one extra python module - sympy. Sympy is able to display mathematical formulas, via the Latex-capable MathJax library, to solve equations and the like.Overall this book is a very interesting read and is packed with information, examples and very useful references. I recommend it to anyone wanting an overview of Python/IPython capabilities for data visualization.An inspiring book?Well yes, I'm inspired to delve deeper into IPython and its use in various data analytic domains, I'm also inspired to use the examples for teaching workshops.
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.