This document summarizes a presentation given by Diane Mueller from ActiveState and Dr. Mike Müller from Python Academy. It compares MATLAB and Python capabilities for scientific computing. Python has many libraries like NumPy, SciPy, IPython and matplotlib that provide similar functionality to MATLAB. Together these are often called "Pylab". The presentation provides an overview of Python, NumPy arrays, visualization with matplotlib, and integrating Python with other languages.
Take Quality Products to Market Faster with Enterprise-Ready Dynamic Languages
Migrating from matlab to python
1.
2. About the Speakers
Diane Mueller
Director, Enterprise Product
Management at ActiveState
DianeM@ActiveState.com
Dr. Mike Müller
CEO, Python Academy
mmueller@python-academy.de
3. Agenda
• About ActiveState & Python Academy
• Quick Comparison of Matlab & Python
• Deep Dive into Python’s "Pylab" functionality
• Includes: Python Basics, NumPy, SciPy, IPython, matplotlib
• Other considerations
• Q&A
4. About ActiveState
• Founded 1997
• 2 million developers, 97% of Fortune 1000 rely on ActiveState
• Development, management, distribution solutions for dynamic
languages
• Core languages: Python, Perl, Tcl
• Other: PHP, Ruby, Javascript
5. About Python Academy
• specialist for Python training
• open and custom courses
• Python for programmers
• Python for scientists and engineers
• many more advanced topics (extensions, databases, GUI,
web)
• Python consulting
8. Quick Comparison Python - "Pylab"
MATLAB • Open Source
• High-level language
• Proprietary to Mathworks
• Tools for building your
• High-level language
own "PyLab"
• interactive environment
• With custom graphical
• Deep computational user interfaces
libraries
• And interactive tools for
• Visualizations iterative exploration,
design, and problem
• Workbench
solving
• Multiple Development
environments available
9. Python - Origin
• 1989/1990 Guido van Rossum
• in between C and shell scripting
• ideas from ABC, C, Smalltalk,
Java, (Haskell)
• 1999 version 1.5.2
• now at 2.7 / 3.1 (3.2beta)
• Python Software Foundation
10. Open Source
• Python license
• Python Software Foundation
• core developers
• developers of third party libraries
• Python Enhancement Proposals (PEP)
11. Features
• simple
• consistent
• readable
• general purpose programming language
• research and implement in the same language
• yet good replacement for MATLAB (NumPy + matplotlib +
IPython + SciPy)
• can do way more than MATLAB
12. Users
• Open Source
• Google (core developers)
• YouTube
• German Aerospace Center
• NASA
• Walt Disney
• Rackspace
• Financial sector (AQR)
• ...
13. Users
• programming novices
• professional software developers
• tester
• system admins
• scientists and engineers, quants
• Python scales
• easy to get started with
• many advanced features if needed (meta programming)
15. Popularity
• easy to get started with
• MIT uses Python for "Introduction to CS and Programming"
• Michigan State replaced C++ successfully with Python
• embedded in Blender, Open Office, Inkscape, Gimp
• its just fun for lots of people
16. Operating Systems
• Windows
• Linux
• Mac
• Main-Frames
• Mobile
• DOS
17. Technology
• interpreter
• platform independent bytecode
• everything at run time
• simple meta-programming
18. Implementations
• CPython == Standard Python
• Jython in Java
• IronPython in C#
• PyPy in Python
• Stackless
• more
19. Example of File IO
the file data.txt:
a b c
1 2 3
4 5 6
7 8 9
20. Example of File IO
>>> fobj = open('data.txt')
>>> header = fobj.next().split()
>>> header
['a', 'b', 'c']
>>> for line in fobj:
... numbers.append([int(entry) for entry in line.split()])
...
>>> numbers
[[1, 2, 3], [4, 5, 6], [7, 8, 9]]
21. Connecting to Your Data Sources
• csv module in standard library
• read and write Excel files (xlrd, xlwt)
• or use COM with MS Office
• read and write HDF5 files (PyTables, h5py)
• netCDF (pynetcdf, nectdf4-python, pupynere)
• binary files (struct from standard library)
• more (just google for desired format and Python)
22. Databases
• connect to all major database
• Oracle
• SQL-Server
• MySQL
• PostgresSQL
• DB2
• SQLite
• more
23. Object Relational Mappers
• SQLAlchemy
• SQLObject
• use object-oriented programming
• no need to write SQL by hand
• no SQL injection
24. NumPy
• work with numeric arrays
• MATLAB-like features
• implemented in C
• fast
• interactive
• 21 data types
42. Properties
In [1]: x = arange(100)
In [2]: linear = x
In [3]: square = arange(0, 10, 0.1) ** 2
In [4]: lines = plot(x, linear, 'g:+', x, square, 'r--o')
In [5]: leg = legend(('linear', 'square'), loc='upper left')
44. Ticks and Formatters
In [6]: major_locator = MultipleLocator(10)
In [7]: major_formatter = FormatStrFormatter('%5.2f')
In [8]: minor_locator = MultipleLocator(5)
In [9]: ax = gca()
In [10]: ax.xaxis.set_major_locator(major_locator)
In [11]: ax.xaxis.set_minor_locator(minor_locator)
In [12]: ax.xaxis.set_major_formatter(major_formatter)
In [13]: draw()
48. Pylab is no total replacement MATLAB (yet)
• Pylab = NumPy + SciPy + IPython + matplotlib
• no Simulink
• documentation, especially for SciPy not as comprehensive but
growing
• no equivalent library for all toolboxes
• smaller user-base but growing
• array and matrix distinction can cause more verboseness
49. Pylab is no total replacement MATLAB (yet)
• same functionality sometimes duplicated
• finding the right library might take some time
• IDEs not as polished, less support for profiling
50. Python is no Island
• extensible in C/C++, Java, C#
• SWIG, SIP, Boost.Python
• .NET, COM
• Cython
• embedding
• access DLLS / shared libraries
51. C/C++ integration with Cython
• call C-functions
cdef extern from "math.h":
double sin(double)
cdef double f(double x):
return sin(x*x)
• works also with C++
52. Glue Language
• connect (heterogeneous) systems
• generate input data
• start and control processes
• read output data
• communicate over the network
• ...
• fast, few lines of code
54. More Scientific Libraries
• RPy /RPy2 (use the R language from Python)
• Scikits (times series and many others)
• pandas (time series and statistical analysis)
• SAGE (free open source alternative to Magma, Maple,
Mathematica and Matlab.)
• PyPi - 766 packages for science and engineering
55. What else?
• standard library - batteries included
• Python Package Index: > 12.000 packages
• wrapper for GUI-Toolkits (wxPython, PyQt, Tkinter etc.)
• web frameworks (Django, Zope, TurboGears, Pylons etc.)
• access to all major database systems
• useful library for nearly all purposes
56. Thank you! Questions?
• Questions?
• Next Steps:
• Find out more about ActivePython Business Edition:
http://www.activestate.com/activepython
• Download ActivePython:
http://www.activestate.com/activepython/downloads
• Request Information:
Business-Solutions@activestate.com or 1-866-510-2914