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 Notebook Essentials
IPython Notebook Essentials

IPython Notebook Essentials: Compute scientific data and execute code interactively with NumPy and SciPy

Arrow left icon
Profile Icon Martins
Arrow right icon
Can$12.99 Can$39.99
Full star icon Full star icon Full star icon Half star icon Empty star icon 3.7 (3 Ratings)
eBook Nov 2014 190 pages 1st Edition
eBook
Can$12.99 Can$39.99
Paperback
Can$49.99
Subscription
Free Trial
Arrow left icon
Profile Icon Martins
Arrow right icon
Can$12.99 Can$39.99
Full star icon Full star icon Full star icon Half star icon Empty star icon 3.7 (3 Ratings)
eBook Nov 2014 190 pages 1st Edition
eBook
Can$12.99 Can$39.99
Paperback
Can$49.99
Subscription
Free Trial
eBook
Can$12.99 Can$39.99
Paperback
Can$49.99
Subscription
Free Trial

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 Notebook Essentials

Chapter 2. The Notebook Interface

The IPython notebook has an extensive user interface that makes it appropriate for the creation of richly formatted documents. In this chapter, we will thoroughly explore the notebook's capabilities. We will also consider the pitfalls and best practices of using the notebook.

In this chapter, the following topics will be covered:

  • Notebook editing and navigation, which includes cell types; adding, deleting, and moving cells; loading and saving notebooks; and keyboard shortcuts
  • IPython magics
  • Interacting with the operating system
  • Running scripts, loading data, and saving data
  • Embedding images, video, and other media with IPython's rich display system

Editing and navigating a notebook

When we open a notebook (by either clicking on its name in the dashboard or creating a new notebook), we see the following in the browser window:

Editing and navigating a notebook

In the preceding screenshot, from the top to the bottom, we see the following components:

  • The Title bar (area marked 1) that contains the name of the notebook (in the preceding example, we can see Chapter 2) and information about the notebook version
  • The Menu bar (area marked 2) looks like a regular application menu
  • The Toolbar (area marked 3) is used for quick access to the most frequently used functionality
  • In the area marked 4, an empty computation cell is shown

Starting with IPython Version 2.0, the notebook has two modes of operation:

  • Edit: In this mode, a single cell comes into focus and we can enter text, execute code, and perform tasks related to that single cell. The Edit mode is activated by clicking on a cell or pressing the Enter key.
  • Command: In this mode, we perform tasks related to the whole notebook structure...

IPython magics

Magics are special instructions to the IPython interpreter that perform specialized actions. There are two types of magics:

  • Line-oriented: This type of magics start with a single percent (%) sign
  • Cell-oriented: This type of magics start with double percent (%%) signs

We are already familiar with one of the magic command, that is, %pylab inline. This particular magic does two of the following things: it imports NumPy and matplotlib, and sets up the notebook for inline plots. To see one of the other options, change the cell to %pylab.

Run this cell and then run the cell that produces the plot again. Instead of drawing the graph inline, IPython will now open a new window with the plot as shown in the following screenshot:

IPython magics

This window is interactive and you can resize the graph, move it, and save it to a file from here.

Another useful magic is %timeit, which records the time it takes to run a line of Python code. Run the following code in a new cell in the notebook:

%timeit return_on_investment...

Interacting with the operating system

Any code with some degree of complexity will interact with the computer's operating system when files must be opened and closed, scripts must be run, or online data must be accessed. Plain Python already has a lot of tools to access these facilities, and IPython and the notebook add another level of functionality and convenience.

Saving the notebook

The notebook is autosaved in periodic intervals. The default interval is 2 minutes, but this can be changed in the configuration files or using the %autosave magic. For example, to change the autosave interval to 5 minutes, run the following command:

%autosave 300

Notice that the time is entered in seconds. To disable the autosave feature, run the following command:

%autosave 0

We can also save the notebook using the File menu or by clicking on the disk icon on the toolbar. This creates a checkpoint. Checkpoints are stored in a hidden folder and can be restored from the File menu. Notice that only the latest...

Running scripts, loading data, and saving data

When working with projects of some complexity, it is common to have the need to run scripts written by others. It is also always necessary to load data and save results. In this section, we will describe the facilities that IPython provides for these tasks.

Running Python scripts

The following Python script generates a plot of a solution of the Lorenz equations, a famous example in the theory of chaos. If you are typing the code, do not type it in a cell in the notebook. Instead, use a text editor and save the file with the name lorenz.py in the same directory that contains the notebook file. The code is as follows:

import numpy as np
import matplotlib.pyplot as plt
from scipy.integrate import odeint
from mpl_toolkits.mplot3d import Axes3D

def make_lorenz(sigma, r, b):
    def func(statevec, t):
        x, y, z = statevec
        return [ sigma * (y - x),
                 r * x - y - x * z,
                 x * y - b * z ]
    return func
  ...

The rich display system

In an exciting development, recent versions of IPython include the capability to display images, video, sound, and other media directly in the notebook. The classes that support the display system are in the IPython.display module. In this section, we will discuss some of the supported formats.

Images and YouTube videos

Images can be loaded either from the local filesystem or from the web. To display the image contained in the character.png file, for example, run the following command in a cell:

from IPython.display import Image
Image('character.png')

It is also possible to store the image in a variable to be displayed at a later time:

img = Image('character.png')

The character.png file can be downloaded from the web page of this book.

To display the image, we can use either img or display(img). The following image is displayed:

Images and YouTube videos

To load an image from the Web, simply give its URL as an argument:

Image('http://www.imagesource.com/Doc/IS0/Media/TR5...

Editing and navigating a notebook


When we open a notebook (by either clicking on its name in the dashboard or creating a new notebook), we see the following in the browser window:

In the preceding screenshot, from the top to the bottom, we see the following components:

  • The Title bar (area marked 1) that contains the name of the notebook (in the preceding example, we can see Chapter 2) and information about the notebook version

  • The Menu bar (area marked 2) looks like a regular application menu

  • The Toolbar (area marked 3) is used for quick access to the most frequently used functionality

  • In the area marked 4, an empty computation cell is shown

Starting with IPython Version 2.0, the notebook has two modes of operation:

  • Edit: In this mode, a single cell comes into focus and we can enter text, execute code, and perform tasks related to that single cell. The Edit mode is activated by clicking on a cell or pressing the Enter key.

  • Command: In this mode, we perform tasks related to the whole notebook...

Left arrow icon Right arrow icon

Description

If you are a professional, student, or educator who wants to learn to use IPython Notebook as a tool for technical and scientific computing, visualization, and data analysis, this is the book for you. This book will prove valuable for anyone that needs to do computations in an agile environment.

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Nov 21, 2014
Length: 190 pages
Edition : 1st
Language : English
ISBN-13 : 9781783988358
Category :
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 : Nov 21, 2014
Length: 190 pages
Edition : 1st
Language : English
ISBN-13 : 9781783988358
Category :
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 Can$6 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 Can$6 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total Can$ 189.97
Python Data Analysis
Can$69.99
IPython Notebook Essentials
Can$49.99
IPython Interactive Computing and Visualization Cookbook
Can$69.99
Total Can$ 189.97 Stars icon
Banner background image

Table of Contents

9 Chapters
1. A Tour of the IPython Notebook Chevron down icon Chevron up icon
2. The Notebook Interface Chevron down icon Chevron up icon
3. Graphics with matplotlib Chevron down icon Chevron up icon
4. Handling Data with pandas Chevron down icon Chevron up icon
5. Advanced Computing with SciPy, Numba, and NumbaPro Chevron down icon Chevron up icon
A. IPython Notebook Reference Card Chevron down icon Chevron up icon
B. A Brief Review of Python Chevron down icon Chevron up icon
C. NumPy Arrays 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.7
(3 Ratings)
5 star 0%
4 star 66.7%
3 star 33.3%
2 star 0%
1 star 0%
Al Sweigart Dec 17, 2014
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
IPython Notebook Essentials is a solid introduction to IPython Notebook that I would recommend for scientists or others who need to learn to code for their job. IPython Notebook itself is a sort of hybrid of Excel, MATLAB, and Python IDE, and this book touches on a wide range of related topics.Don't mistake this book for simply covering just IPython on Notebook. The first two chapters teach you the ropes of the software, and the later chapters cover generating graphs with matplotlib, processing & analyzing data with Pandas (a Python software library), and doing more advanced mathematics with the SciPy, Numba, and NumbaPro libraries.IPython Notebook Essentials is a light introduction (IPython itself is fairly easy to pick up), but the strength of the book is that it brings the reader into contact with several related libraries. The examples in the book might not be exactly relevant to your field, but the skills they demonstrate will be. Following along with them on your own computer will let you get the most from this book.The main criticism I would have of the book is that it is wide but not deep. But if you understand this going into the book, you won't be disappointed.If you want to learn programming in general, this is not the book for you. If you don't mind haphazardly sorting through free tutorials on the web, then you can learn the same concepts that are presented in this book. But if you are in the particular niche of scientist or administrator who needs to do number crunching, has a small amount of previous Python programming experience, and want a light introduction to the Python ecosystem of data analysis tools, IPython Notebook Essentials is a good start.Disclosure: I received a free ebook review copy of IPython Notebook Essentials from Packt Publishing for the purposes of writing this review. I do not have any business ties to Packt Publishing.
Amazon Verified review Amazon
Mike Driscoll Dec 04, 2014
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
The book starts out by giving the reader a tour of the IPython Notebook in chapter one. The author recommends that you use the Anaconda distribution of Python and that you sign up for Wakari to make sharing Notebooks easier. Then you learn how to run a notebook and the author goes into an example using a coffee cooling algorithm. That may sound a little strange, but it was actually pretty interesting to learn about how to calculate how much coffee cools over time. I also thought it was a good way to demonstrate the Notebook’s capabilities. The chapter ends with a few brief exercises.In chapter two, we learn more about the Notebook’s interface. Here we learn how to edit and navigate the Notebook and IPython magics. You will also learn how to run script and load and save data. The chapter ends with a few examples showing how to embed images, Youtube videos and HTML in your Notebook. I liked this chapter quite a bit.For chapter three, we change gears dramatically. From this point on until we reach the appendices, the book is basically for scientists. This chapter is about creating plots and animations with Matplotlib inside the Notebook. The Notebook itself is rarely discussed.Chapter four is all about the pandas project, which is a powerful library for data handling and analytics. This is outside my field, so I cannot comment on its accuracy, let alone understand everything the author writes about in this chapter. Suffice it to say, I only skimmed chapter four.Chapter five is about SciPy, Numba and NumbaPro. Once again, the focus is on scientific computations (SciPy) and how to accelerate those computations (Numba/NumbaPro). I skipped this chapter too.The Appendices cover the following: An IPython Notebook Reference Card, A brief overview of the Python language, and NumPy Arrays.Going into this book, I assumed that it would be a guide to the IPython Notebook. The title certainly gives one that impression. However, the majority of the book is not about the IPython Notebook at all and instead focuses on scientific computing with Python. There are many other books that cover that topic and perhaps the IPython Notebook is used mostly by scientists. The preface states that the book is supposed to be learning about the Notebook too along with some of these other libraries. I just felt that the scientific libraries got the majority of the prose and the Notebook got short shrift.If you are looking for a guide to the IPython Notebook, I’m not sure I can recommend this book for you. It only has 2 chapters that focus exclusively on that topic plus a reference card in the appendix. On the other hand, if you are looking for a very brief overview of some of the scientific libraries you can use in Python plus learn how to use the IPython Notebook in general, then this might be the book for you.
Amazon Verified review Amazon
Matteo Jan 18, 2015
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3
The book is supposed to make you learn ipython by throwing you into a field course of examples but the explanations are not on the same level in all the examples, some are well documented and easy to read others are a bit too cryptic for a newcomer. Try using this book along with some other books if you are not well versed in the language but keep in mind that the code samples are based on python 2.7, if you want to learn or have a set of language samples/examples using the 3.x branch you should use Cyrille Rossant's books from the same publisher.
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.