the joy of scipy, part i

16
The Joy of SciPy Part I, Dinu Gherman Part II, Dave Kammeyer (not included here) Python Users Berlin Meet-up, 2013-02-14

Upload: dinugherman

Post on 27-Jan-2015

111 views

Category:

Documents


0 download

DESCRIPTION

 

TRANSCRIPT

Page 1: The Joy of SciPy, Part I

The Joy of SciPy

Part I, Dinu GhermanPart II, Dave Kammeyer (not included here)

Python Users BerlinMeet-up, 2013-02-14

Page 2: The Joy of SciPy, Part I

About…Science…

Data

Big Data

Analytics

Machine Learning

… and Python

Visualisation

Numbers

MathAlgorithms

Page 3: The Joy of SciPy, Part I

Science, a ReminderDomains

Data

Theory

Models

EducationMath

Experiments

Visualisation

Publication

Page 4: The Joy of SciPy, Part I

From ScientificPython “Components”…

SphinxReST (sample)

MatplotlibChacoVeusz…

SymPyNumPyBlaze

Nat. Language ToolkitMol. Modelling ToolkitBioPython.orgPsychoPy.orgAstroPython.org

StacklessPyPyCythonNumbaTheano

PandasPyTablesDisco

Scikit-learn…

PILOpenCVScikit-image

… … …

Page 5: The Joy of SciPy, Part I

… to IntegratedScientific Environments

Legacy:

Mathematica

Matlab

Maple

Magma

Py-Environments:

IPython.org

SciPy.org

Sagemath.org

Wakari.io

Mathics.org

Orange

Py-Distributions:

ScientificPython

Enthought, EPD

Anaconda

Python(x, y)

Page 6: The Joy of SciPy, Part I

IPython Shell

• Extended Inter- active Python shell

• Tab completion

• Multi-line editing

• Shell access

• Magic functions

• Extensions

• Help

• History

• Debugger

• Bookmarks

• DEMO…

Page 7: The Joy of SciPy, Part I

IPython Notebook

• IPython shell in the browser

• Markdown text + executable Python code

• JSON container, including output

• Literate Programming – finally

• Great tutorial experience

• Easy to share running code – w/o hassle

Page 8: The Joy of SciPy, Part I

IPython Notebook Demo

• Tour of the IPython notebook (built-in)

• Installing a custom extension

• Combined later with Matplotlib demo

Page 9: The Joy of SciPy, Part I

IPython Extension Demo

• Show object graphs

• Reuse a previously written package

• Run interactively in the notebook

• Notebook:http://nbviewer.ipython.org/4770302/

• Code:https://gist.github.com/deeplook/4731035

Page 10: The Joy of SciPy, Part I

Matplotlib

• Scientific plots

• 2D, 3D, interactive

• Smart axes, grids

• Beautiful math (TeX)

• Widgets, annotations, …

• http://matplotlib.org/gallery.html

Page 11: The Joy of SciPy, Part I

Matplotlib Demo

• Simple plots

• Bézier path editor

• Magic cube

Page 12: The Joy of SciPy, Part I

Conferences

• http://conference.scipy.org

• https://www.euroscipy.org

• http://pydata.org

Videos (e.g. by John Hunter , Fernando Pérez et al.):http://pyvideo.org/category/17/pycon-us-2012

Page 13: The Joy of SciPy, Part I

Selected Books

Page 14: The Joy of SciPy, Part I

What to take away

• Use available Python tools for your scientific domain (trivia)!

• Use IPython shell & notebook, Matplotlib– far too powerful to leave to scientists! ;-)

• Have fun with science – seriously!

http://io9.com/5973726/15+year-old-whiz-kid-has-research-on-dwarf-galaxies-published-in-nature

Page 15: The Joy of SciPy, Part I

Questions?Exercise?

Page 16: The Joy of SciPy, Part I

ExerciseRun the algorithm below using CPython, Cython, PyPy and Numba and compare their performance. This is implementing a spigot algorithm by A. Sale, D. Saada, S. Rabinowitz, as mentioned onhttp://mail.python.org/pipermail/edu-sig/2012-December/010721.html.Code: https://gist.github.com/deeplook/4947835.

def pi_digits(n): "Generate n digits of Pi." k, a, b, a1, b1 = 2, 4, 1, 12, 4 while n > 0: p, q, k = k * k, 2 * k + 1, k + 1 a, b, a1, b1 = a1, b1, p * a + q * a1, p * b + q * b1 d, d1 = a / b, a1 / b1 while d == d1 and n > 0: yield int(d) n -= 1 a, a1 = 10 * (a % b), 10 * (a1 % b1) d, d1 = a / b, a1 / b1

>>> list(pi_digits(20))[3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 8, 9, 7, 9, 3, 2, 3, 8, 4]