This flexible style matches well the spirit of computing in a scientific context, in which determining what computations must be performed next often requires significant work. An interactive environment lets scientists look at data, test new ideas, combine algorithmic approaches, and evaluate their outcomes directly.
IPython is an enhanced Python shell for interactive distributed and parallel computing. When users are testing new ideas and algorithms in computer vision, evaluating the results directly, in an interactive way, is more convenient than the traditional compile-then-execute cycle. A live computing state is convenient because previous intermediate results (images, feature vectors, parameters) are kept available for exploration. Pérez and Granger argue that, in a research context, determining which computations must be performed next often requires significant work.
In an interactive computing system, users should have access to all session state. In
IPython, this access is not just provided by the dynamically attributed variables, but also by numbered output prompts. Previous computations can be retrieved using and underscore "
_" and the number of the output.
Other useful capabilities in IPython are
TAB completion and system shell integration.
When the user types the
TAB key, IPython tries to complete the current prompt with keywords or the names of methods, variables and files in the current directory. This is particularly useful when exploring unfamiliar or large APIs as in OpenCV or in the SciPy library. Regarding system shell integration, IPython cannot only call any system command, but also can capture the shell’s output in Python variables and call system commands with values computed from variables.
Call a system's command:
Store the command output in a Python variable:
Call a system's command passing arguments stored in Python variables:
%save- load/save code into/from IPython
%run- run a Python file inside IPython as a program
%who- list all interactive variables
%timeit- time execution of a Python statement or expression
Create a random @@0@@ matrix @@1@@ and time the Singular Value Decompostion (SVD) @@2@@.
Timing 2D features detection (SIFT vs. SURF)
The IPython Notebook is a web-based version of the IPython shell presenting extended functionality. In the notebook, the user can organize formatted text and code blocks in a flexible way. Text and code are organized in cells that can be inserted, deleted, rearranged and executed as needed. IPython notebooks can handle plots, mathematical formulas and code output, everything organized in a single executable document. Notebooks are being used for research notes, and on the production of articles and books.
In a notebook, a Markdown cell is able the render rich-formatted text using the Markdown markup convention. Mathematical notation is defined using LaTeX syntax and rendered by MathJax.
1 2 3 4
Let @@0@@ and @@1@@ be the mean and the standard deviation of a grayscale image @@2@@. The whitening operation is defined by: @@3@@.
Let @@4@@ and @@5@@ be the mean and the standard deviation of a grayscale image @@6@@. The whitening operation is defined by:
Code cells contain Python code that is sent to the IPython interpreter running on the server, executed, and the resulting output sent back to the browser for exhibition. That means that IPython can be running in a powerful machine like a server while the user is able to perform her work from a leaner system as a laptop or a tablet. If the result of a code block is a plot, it can be exhibited inside the notebook in the browser (inline plotting).
Can be converted to:
For details, check:
$ jupyter nbconvert --help
IPython notebooks are stored in JSON files that keep the cells’ content. These files uses the extension
.ipynb and can be exported as Python scripts, HTML documents or even printed. But what makes notebook files suitable to reproducible research is the fact they are executable documents, not only able to store textual and mathematical descriptions but also replicate the computations.
The IPython default console (terminal) can be started using:
1 2 3 4 5 6 7 8 9 10 11
$ ipython Python 2.7.6 (default, Mar 22 2014, 22:59:56) Type "copyright", "credits" or "license" for more information. IPython 2.1.0 -- An enhanced Interactive Python. ? -> Introduction and overview of IPython's features. %quickref -> Quick reference. help -> Python's own help system. object? -> Details about 'object', use 'object??' for extra details. In :
Other alternative is qtconsole, a console running on a graphical window:
$ ipython qtconsole
To run notebooks, use jupyter:
1 2 3 4 5 6 7 8
$ jupyter notebook [NotebookApp] Using existing profile dir: u'/home/thiago/.ipython/profile_default' [NotebookApp] Using MathJax from CDN: http://cdn.mathjax.org/mathjax/latest/MathJax.js [NotebookApp] Serving notebooks from local directory: /home/thiago [NotebookApp] 0 active kernels [NotebookApp] The IPython Notebook is running at: http://localhost:8888/ [NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
Ctrl-Cto stop the server and shutdown kernels