Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
IPython Interactive Computing and Visualization Cookbook
IPython Interactive Computing and Visualization Cookbook

IPython Interactive Computing and Visualization Cookbook: Over 100 hands-on recipes to sharpen your skills in high-performance numerical computing and data science in the Jupyter Notebook , Second Edition

eBook
$9.99 $29.99
Paperback
$38.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

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:

  • Learning the basics of the Unix shell
  • Using the latest features of Python 3
  • Learning the basics of the distributed version control system Git
  • A typical workflow with Git branching
  • Efficient interactive computing workflows with IPython
  • Ten tips for conducting reproducible interactive computing experiments
  • Writing high-quality Python code
  • Writing unit tests with pytest
  • Debugging code with IPython

Introduction

This is a special chapter about good practices in interactive computing. It describes how to work efficiently and properly with the tools this book is about. We will introduce common tools such as the Unix shell, the latest features of Python 3, and Git, before tackling reproducible computing experiments (notably with the Jupyter 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.

Learning the basics of the Unix shell

Learning how to interact with the operating system using a command-line interface (or Terminal) is a required skill in interactive computing and data analysis. We will use a command-line interface in most of the recipes in this book. IPython and the Jupyter Notebook are typically launched from a Terminal. Installing Python packages is typically done from a Terminal.

In this recipe, we will show the very basics of the Unix shell, which is natively available in Linux distributions (such as Debian, Ubuntu, and so on) and macOS. On Windows 10, one can install the Windows Subsystem for Linux, a command-line interface to a Unix subsystem integrated with the Windows operating system (see https://docs.microsoft.com/windows/wsl/about).

Getting ready

Here are the instructions to open a Unix shell on macOS, Linux, and Windows. Bash is the most common Unix shell and this is what we will use in this recipe.

On macOS, bring up the Spotlight Search, type terminal, and...

Using the latest features of Python 3

The latest version of the Python 2.x branch, Python 2.7, was released in 2010. It will reach its end of life in 2020. On the other hand, the first version of the Python 3.x branch, Python 3.0, was released in 2008. The decade-long transition period between Python 2 and Python 3, which are slightly incompatible, has been somewhat chaotic.

Choosing between Python 2 (also known as Legacy Python) and Python 3 used to be tricky since many Python users had not transitioned to Python 3 yet, and many libraries were only compatible with Python 2. Those times are gone and it is now safe to stick with Python 3 in virtually all cases. The only exceptions are when you have to support old unmaintained libraries, or when your users cannot transition to Python 3 for whatever reason.

In addition to fixing the bugs and annoyances of Python 2 (for example, related to Unicode support), Python 3 brings many interesting features in terms of syntax, capabilities of the language...

Learning the basics of the distributed version control system Git

Using a version control system is an absolute requirement in programming and research. This is the tool that makes it just about impossible to lose one's work. In this recipe, we will cover the basics of Git.

Getting ready

Notable distributed version control systems include Git, Mercurial, and Bazaar, among others. In this chapter, we will use the popular Git system. You can download the Git program and Git GUI clients from http://git-scm.com.

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.

An online provider allows you to host your code in the cloud. You can use it as a backup of your work and as a platform to share your code with your colleagues. These services include GitHub (https://github.com), GitLab (https://gitlab.com), and Bitbucket (https://bitbucket.org). All of these websites...

A typical workflow with Git branching

A distributed version control system such as Git is designed for the complex and nonlinear workflows that are 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 go to the myproject repository and we create a new branch named newidea:
    $ pwd
    /home/cyrille/git/cookbook-2nd/chapter02
    $ cd myproject
    $ git branch newidea
    $ git branch
    * master
      newidea
    

    As indicated by the star *, we are still on the master branch.

  2. We switch to the newly-created newidea branch:
    $ git checkout newidea
    Switched to branch 'newidea'
    $ git branch
      Master
    * newidea
    
  3. We make changes to the code, for instance, by creating a new file:
    $ echo "print('new')" > newfile.py
    $ cat newfile.py
    print(&apos...

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:

  1. Write some code
  2. Execute it
  3. Interpret the results
  4. Repeat

This fundamental loop (also known as Read-Eval-Print Loop (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...

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. It describes how to work efficiently and properly with the tools this book is about. We will introduce common tools such as the Unix shell, the latest features of Python 3, and Git, before tackling reproducible computing experiments (notably with the Jupyter 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.

Learning the basics of the Unix shell


Learning how to interact with the operating system using a command-line interface (or Terminal) is a required skill in interactive computing and data analysis. We will use a command-line interface in most of the recipes in this book. IPython and the Jupyter Notebook are typically launched from a Terminal. Installing Python packages is typically done from a Terminal.

In this recipe, we will show the very basics of the Unix shell, which is natively available in Linux distributions (such as Debian, Ubuntu, and so on) and macOS. On Windows 10, one can install the Windows Subsystem for Linux, a command-line interface to a Unix subsystem integrated with the Windows operating system (see https://docs.microsoft.com/windows/wsl/about).

Getting ready

Here are the instructions to open a Unix shell on macOS, Linux, and Windows. Bash is the most common Unix shell and this is what we will use in this recipe.

On macOS, bring up the Spotlight Search, type terminal, and...

Using the latest features of Python 3


The latest version of the Python 2.x branch, Python 2.7, was released in 2010. It will reach its end of life in 2020. On the other hand, the first version of the Python 3.x branch, Python 3.0, was released in 2008. The decade-long transition period between Python 2 and Python 3, which are slightly incompatible, has been somewhat chaotic.

Choosing between Python 2 (also known as Legacy Python) and Python 3 used to be tricky since many Python users had not transitioned to Python 3 yet, and many libraries were only compatible with Python 2. Those times are gone and it is now safe to stick with Python 3 in virtually all cases. The only exceptions are when you have to support old unmaintained libraries, or when your users cannot transition to Python 3 for whatever reason.

In addition to fixing the bugs and annoyances of Python 2 (for example, related to Unicode support), Python 3 brings many interesting features in terms of syntax, capabilities of the language...

Left arrow icon Right arrow icon

Key benefits

  • • Leverage the Jupyter Notebook for interactive data science and visualization
  • • Become an expert in high-performance computing and visualization for data analysis and scientific modeling
  • • A comprehensive coverage of scientific computing through many hands-on, example-driven recipes with detailed, step-by-step explanations

Description

Python is one of the leading open source platforms for data science and numerical computing. IPython and the associated Jupyter Notebook offer efficient interfaces to Python for data analysis and interactive visualization, and they constitute an ideal gateway to the platform. IPython Interactive Computing and Visualization Cookbook, Second Edition contains many ready-to-use, focused recipes for high-performance scientific computing and data analysis, from the latest IPython/Jupyter features to the most advanced tricks, to help you write better and faster code. You will apply these state-of-the-art methods to various real-world examples, illustrating topics in applied mathematics, scientific modeling, and machine learning. The first part of the book covers programming techniques: code quality and reproducibility, code optimization, high-performance computing through just-in-time compilation, parallel computing, and graphics card programming. The second part tackles data science, statistics, machine learning, signal and image processing, dynamical systems, and pure and applied mathematics.

Who is this book for?

This book is intended for anyone interested in numerical computing and data science: students, researchers, teachers, engineers, analysts, and hobbyists. A 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

  • • Master all features of the Jupyter Notebook
  • • Code better: write high-quality, readable, and well-tested programs; profile and optimize your code; and conduct reproducible interactive computing experiments
  • • Visualize data and create interactive plots in the Jupyter Notebook
  • • Write blazingly fast Python programs with NumPy, ctypes, Numba, Cython, OpenMP, GPU programming (CUDA), parallel IPython, Dask, and more
  • • Analyze data with Bayesian or frequentist statistics (Pandas, PyMC, and R), and learn from actual data through machine learning (scikit-learn)
  • • Gain valuable insights into signals, images, and sounds with SciPy, scikit-image, and OpenCV
  • • Simulate deterministic and stochastic dynamical systems in Python
  • • Familiarize yourself with math in Python using SymPy and Sage: algebra, analysis, logic, graphs, geometry, and probability theory

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Jan 31, 2018
Length: 548 pages
Edition : 2nd
Language : English
ISBN-13 : 9781785881930
Category :
Languages :
Concepts :
Tools :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Jan 31, 2018
Length: 548 pages
Edition : 2nd
Language : English
ISBN-13 : 9781785881930
Category :
Languages :
Concepts :
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
Python Web Scraping Cookbook
$43.99
Jupyter Cookbook
$43.99
IPython Interactive Computing and Visualization Cookbook
$38.99
Total $ 126.97 Stars icon
Banner background image

Table of Contents

16 Chapters
1. A Tour of Interactive Computing with Jupyter and IPython Chevron down icon Chevron up icon
2. Best Practices in Interactive Computing Chevron down icon Chevron up icon
3. Mastering the Jupyter 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. Data 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.4
(7 Ratings)
5 star 42.9%
4 star 57.1%
3 star 0%
2 star 0%
1 star 0%
Filter icon Filter
Top Reviews

Filter reviews by




gary d. smith Jul 28, 2018
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Excellent for my needs as a beginner with Jupyter. very well written. definitely recommend.
Amazon Verified review Amazon
User0910 May 13, 2020
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Le livre va bien au-delà d'IPython et semble en fait s'adresser au scientifique ayant déjà une pratique de python en lui proposant de mettre à jour ses connaissances sur l'écosystème de Python gravitant en gros autour du calcul numérique.Dans l'absolu, le livre est un peu touche à tout, balayant un nombre impressionnant de librairies en 500 pages, là où une seule pourrait faire l'objet d'un livre séparé. D'ordinaire, ce genre d'inventaire à la Prévert a le don d'agacer pour qui n'aime pas le survol.Or ici, un miracle se produit. Peut-être suis-je exactement le lecteur ciblé par l'auteur, mais quasiment chaque section de chaque chapitre fait mouche. Bien qu'utilisant python régulièrement pour mon travail, je m'aperçois à quel point je reste prisonnier des outils que je connais, et combien je suis ignorant de l'incroyable richesse de l'écosystème scientifique et computationel de python.Je n'ai tout simplement jamais mis la main sur un livre contenant une telle densité informative. Bien sûr, aucun sujet n'est réellement approfondi, mais le plus souvent, les librairies ne sont pas simplement mentionnées, mais utilisées dans un exemple informatif qui met le pied à l'étrier.Chapeau à l'auteur pour ses connaissances et sa maîtrise qui transpirent à chaque page de ce livre impressionnant.
Amazon Verified review Amazon
Carol Willing Feb 19, 2018
Full star icon Full star icon Full star icon Full star icon Full star icon 5
The "Cookbook" update adds new content about Jupyter and Python 3.6. It provides a comprehensive, yet understandable, reference to Jupyter, IPython, and frequently used Python data science libraries. The code examples clearly demonstrate how to use popular Python libraries with IPython and Jupyter. Each section contains links to additional resources and provides the reader a wealth of high-quality tips and use cases.I highly recommend the "Cookbook" to people getting started with IPython/Jupyter. The examples and content will also delight current users of IPython/Jupyter. An industry standard, the "Cookbook", is now even better with additional content, updates, and color available for visualizations.
Amazon Verified review Amazon
David E. Jun 04, 2018
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
Very informative cookbook on IPython.
Amazon Verified review Amazon
Amazon Customer May 11, 2018
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
very happy with my book what more can you say !
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.