SlideShare uma empresa Scribd logo
1 de 57
Baixar para ler offline
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
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
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
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
ActiveState Solutions
Packages Include

  • "Pylab": NumPy, SciPy, Matplotlib
  • GUI Toolkits: pyQT, wxPython
  • Database Connectors: Postgres, MySQL, Oracle, MSSQL,
    SqlAlchemy, ODBC
  • Cryptography: M2Crypto
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
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
Open Source

 • Python license
 • Python Software Foundation
 • core developers
 • developers of third party libraries
 • Python Enhancement Proposals (PEP)
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
Users

  • Open Source
  • Google (core developers)
  • YouTube
  • German Aerospace Center
  • NASA
  • Walt Disney
  • Rackspace
  • Financial sector (AQR)
  • ...
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)
Popularity
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
Operating Systems

  • Windows
  • Linux
  • Mac
  • Main-Frames
  • Mobile
  • DOS
Technology

  • interpreter
  • platform independent bytecode
  • everything at run time
  • simple meta-programming
Implementations

  • CPython == Standard Python
  • Jython in Java
  • IronPython in C#
  • PyPy in Python
  • Stackless
  • more
Example of File IO
the file data.txt:


 a      b       c
 1      2       3
 4      5       6
 7      8       9
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]]
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)
Databases

  • connect to all major database
  • Oracle
  • SQL-Server
  • MySQL
  • PostgresSQL
  • DB2
  • SQLite
  • more
Object Relational Mappers

  • SQLAlchemy
  • SQLObject
  • use object-oriented programming
  • no need to write SQL by hand
  • no SQL injection
NumPy

 • work with numeric arrays
 • MATLAB-like features
 • implemented in C
 • fast
 • interactive
 • 21 data types
Create Arrays

 >>> import numpy as np
 >>> a = np.array([[1, 2, 3], [4, 5, 6]])
 >>> a
 array([[1, 2, 3],
        [4, 5, 6]])
 >>> a.shape
 (2, 3)
 >>> a.dtype
 dtype('int32')
 >>> a.size
 6
Create Arrays

 >>> b = np.arange(10)
 >>> b
 array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
 >>> c = np.array([[1, 2, 3], [4, 5, 6]],
                  dtype=np.float32)
 >>> c
 array([[ 1., 2., 3.],
        [ 4., 5., 6.]], dtype=float32)
Create Arrays

>>> np.arange(16, dtype=np.float).reshape(4, 4)
array([[ 0.,    1.,   2.,   3.],
       [ 4.,    5.,   6.,   7.],
       [ 8.,    9., 10., 11.],
       [ 12., 13., 14., 15.]])
>>> np.zeros((3, 4))
array([[ 0., 0., 0., 0.],
       [ 0., 0., 0., 0.],
       [ 0., 0., 0., 0.]])
Create Arrays

 >>> np.ones((3, 4))
 array([[ 1., 1., 1., 1.],
        [ 1., 1., 1., 1.],
        [ 1., 1., 1., 1.]])
 >>> np.zeros((3, 4)) + 5
 array([[ 5., 5., 5., 5.],
        [ 5., 5., 5., 5.],
        [ 5., 5., 5., 5.]])
Data Types

  • 21 data types
  • signed and unsigned integer (8, 16, 32, 64 bit)
  • floats (32, 64 an 96 bit)
  • complex (64, 128, 192 bit)
  • bool
  • string
  • character
  • objects
Data Types

>>> a = np.array([1, 2, 3], dtype=np.int64)
>>> a
array([1, 2, 3], dtype=int64)
>>> a.dtype
dtype('int64')
>>> a.dtype.type
<type 'numpy.int64'>
>>> a.dtype.char
'q'
>>> a.dtype.str
'<i8'
Slicing

 >>> one_d = np.arange(10)
 >>> one_d
 array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
 >>> one_d[0]
 0
 >>> one_d[1]
 1
 >>> one_d[-1]
 9
 >>> one_d[2:5]
 array([2, 3, 4])
Slicing

 >>> two_d = np.arange(25).reshape(5, 5)
 >>> two_d
 array([[ 0, 1, 2, 3, 4],
        [ 5, 6, 7, 8, 9],
        [10, 11, 12, 13, 14],
        [15, 16, 17, 18, 19],
        [20, 21, 22, 23, 24]])
 >>> two_d[0, 0]
 0
 >>> two_d[0]
 array([0, 1, 2, 3, 4])
Slicing

 >>> two_d[:,0]
 array([ 0, 5, 10, 15, 20])
 >>> two_d[1:-1,1:-1]
 array([[ 6, 7, 8],
        [11, 12, 13],
        [16, 17, 18]])


  • advanced selection (integers, booleans, strings)
  • "loop-less" programming
Broadcasting

>>> two_d
array([[ 0,     1,    2, 3, 4],
       [ 5,     6,    7, 8, 9],
       [10,   11,    12, 13, 14],
       [15,   16,    17, 18, 19],
       [20,   21,    22, 23, 24]])
>>> two_d +   5
array([[ 5,     6,    7,    8,    9],
       [10,   11,    12,   13,   14],
       [15,   16,    17,   18,   19],
       [20,   21,    22,   23,   24],
       [25,   26,    27,   28,   29]])
Broadcasting

>>> a = np.arange(8).reshape(2, 4)
>>> a
array([[0, 1, 2, 3],
       [4, 5, 6, 7]])
>>> b = np.arange(4)
>>> b
array([0, 1, 2, 3])
>>> a + b
array([[ 0, 2, 4, 6],
       [ 4, 6, 8, 10]])
Universal Functions
>>> np.sin(a)
array([[ 0.        , 0.84147098, 0.90929743, 0.14112001],
       [-0.7568025 , -0.95892427, -0.2794155 , 0.6569866 ]])
>>> np.sin.nin
1
>>> np.sin.nout
1
>>> np.sin.types
['f->f', 'd->d', 'g->g', 'F->F', 'D->D', 'G->G', 'O->O']
Matrices

  • always 2D

 >>> M = np.matrix('1 2 3; 4 5 6')
 >>> M
 matrix([[1, 2, 3],
         [4, 5, 6]])
 >>> M.I
 matrix([[-0.94444444, 0.44444444],
         [-0.11111111, 0.11111111],
         [ 0.72222222, -0.22222222]])
SciPy

  • big package
  • interpolation
  • linear algebra
  • FFT
  • statistics
  • optimization
  • much more
IPython

  • improved interactive shell
  • object introspection
  • system shell access
  • command system for adding functionality
  • allows interactive work with matplotlib ipython -pylab
Basic matplotlib-plotting

  • simple, yet powerful plotting package

In [1]: plot(random(100))
Out[1]: [<matplotlib.lines.Line2D object at 0x02A3EA90>]
Properties

  • colors
  • line styles
  • markers
  • legend
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')
Properties
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()
Nice Plots
Nice Plots
Nice Plots
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
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
Python is no Island

  • extensible in C/C++, Java, C#
  • SWIG, SIP, Boost.Python
  • .NET, COM
  • Cython
  • embedding
  • access DLLS / shared libraries
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++
Glue Language

  • connect (heterogeneous) systems
  • generate input data
  • start and control processes
  • read output data
  • communicate over the network
  • ...
  • fast, few lines of code
Performance and Future Developments

  • multi-cores
  • multiprocessing (standard library)
  • GPUs
  • theano
  • pyCUDA
  • Clyther
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
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
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
We've Got Your Universe Covered

Mais conteúdo relacionado

Mais procurados

Scoobi - Scala for Startups
Scoobi - Scala for StartupsScoobi - Scala for Startups
Scoobi - Scala for Startupsbmlever
 
Spark schema for free with David Szakallas
Spark schema for free with David SzakallasSpark schema for free with David Szakallas
Spark schema for free with David SzakallasDatabricks
 
Standardizing arrays -- Microsoft Presentation
Standardizing arrays -- Microsoft PresentationStandardizing arrays -- Microsoft Presentation
Standardizing arrays -- Microsoft PresentationTravis Oliphant
 
Python for R developers and data scientists
Python for R developers and data scientistsPython for R developers and data scientists
Python for R developers and data scientistsLambda Tree
 
Php data structures – beyond spl (online version)
Php data structures – beyond spl (online version)Php data structures – beyond spl (online version)
Php data structures – beyond spl (online version)Mark Baker
 
An Introduction to Higher Order Functions in Spark SQL with Herman van Hovell
An Introduction to Higher Order Functions in Spark SQL with Herman van HovellAn Introduction to Higher Order Functions in Spark SQL with Herman van Hovell
An Introduction to Higher Order Functions in Spark SQL with Herman van HovellDatabricks
 
The Arrow Library in Kotlin
The Arrow Library in KotlinThe Arrow Library in Kotlin
The Arrow Library in KotlinGarth Gilmour
 
Keynote at Converge 2019
Keynote at Converge 2019Keynote at Converge 2019
Keynote at Converge 2019Travis Oliphant
 
Coding in Kotlin with Arrow NIDC 2018
Coding in Kotlin with Arrow NIDC 2018Coding in Kotlin with Arrow NIDC 2018
Coding in Kotlin with Arrow NIDC 2018Garth Gilmour
 
Is there a perfect data-parallel programming language? (Experiments with More...
Is there a perfect data-parallel programming language? (Experiments with More...Is there a perfect data-parallel programming language? (Experiments with More...
Is there a perfect data-parallel programming language? (Experiments with More...Julian Hyde
 
Clojure: The Art of Abstraction
Clojure: The Art of AbstractionClojure: The Art of Abstraction
Clojure: The Art of AbstractionAlex Miller
 
SQL Server Select Topics
SQL Server Select TopicsSQL Server Select Topics
SQL Server Select TopicsJay Coskey
 
Python - Numpy/Pandas/Matplot Machine Learning Libraries
Python - Numpy/Pandas/Matplot Machine Learning LibrariesPython - Numpy/Pandas/Matplot Machine Learning Libraries
Python - Numpy/Pandas/Matplot Machine Learning LibrariesAndrew Ferlitsch
 
Introduction to TensorFlow 2.0
Introduction to TensorFlow 2.0Introduction to TensorFlow 2.0
Introduction to TensorFlow 2.0Databricks
 
Python and Data Analysis
Python and Data AnalysisPython and Data Analysis
Python and Data AnalysisPraveen Nair
 

Mais procurados (20)

Scoobi - Scala for Startups
Scoobi - Scala for StartupsScoobi - Scala for Startups
Scoobi - Scala for Startups
 
Spark schema for free with David Szakallas
Spark schema for free with David SzakallasSpark schema for free with David Szakallas
Spark schema for free with David Szakallas
 
Standardizing arrays -- Microsoft Presentation
Standardizing arrays -- Microsoft PresentationStandardizing arrays -- Microsoft Presentation
Standardizing arrays -- Microsoft Presentation
 
Python for R users
Python for R usersPython for R users
Python for R users
 
Python for R developers and data scientists
Python for R developers and data scientistsPython for R developers and data scientists
Python for R developers and data scientists
 
Php data structures – beyond spl (online version)
Php data structures – beyond spl (online version)Php data structures – beyond spl (online version)
Php data structures – beyond spl (online version)
 
An Introduction to Higher Order Functions in Spark SQL with Herman van Hovell
An Introduction to Higher Order Functions in Spark SQL with Herman van HovellAn Introduction to Higher Order Functions in Spark SQL with Herman van Hovell
An Introduction to Higher Order Functions in Spark SQL with Herman van Hovell
 
The Arrow Library in Kotlin
The Arrow Library in KotlinThe Arrow Library in Kotlin
The Arrow Library in Kotlin
 
PyCon Estonia 2019
PyCon Estonia 2019PyCon Estonia 2019
PyCon Estonia 2019
 
Keynote at Converge 2019
Keynote at Converge 2019Keynote at Converge 2019
Keynote at Converge 2019
 
Coding in Kotlin with Arrow NIDC 2018
Coding in Kotlin with Arrow NIDC 2018Coding in Kotlin with Arrow NIDC 2018
Coding in Kotlin with Arrow NIDC 2018
 
Om nom nom nom
Om nom nom nomOm nom nom nom
Om nom nom nom
 
Is there a perfect data-parallel programming language? (Experiments with More...
Is there a perfect data-parallel programming language? (Experiments with More...Is there a perfect data-parallel programming language? (Experiments with More...
Is there a perfect data-parallel programming language? (Experiments with More...
 
Hands on lua
Hands on luaHands on lua
Hands on lua
 
Clojure: The Art of Abstraction
Clojure: The Art of AbstractionClojure: The Art of Abstraction
Clojure: The Art of Abstraction
 
SQL Server Select Topics
SQL Server Select TopicsSQL Server Select Topics
SQL Server Select Topics
 
Python - Numpy/Pandas/Matplot Machine Learning Libraries
Python - Numpy/Pandas/Matplot Machine Learning LibrariesPython - Numpy/Pandas/Matplot Machine Learning Libraries
Python - Numpy/Pandas/Matplot Machine Learning Libraries
 
Introduction to TensorFlow 2.0
Introduction to TensorFlow 2.0Introduction to TensorFlow 2.0
Introduction to TensorFlow 2.0
 
Pandas
PandasPandas
Pandas
 
Python and Data Analysis
Python and Data AnalysisPython and Data Analysis
Python and Data Analysis
 

Semelhante a Migrating from matlab to python

AI與大數據數據處理 Spark實戰(20171216)
AI與大數據數據處理 Spark實戰(20171216)AI與大數據數據處理 Spark實戰(20171216)
AI與大數據數據處理 Spark實戰(20171216)Paul Chao
 
Travis Oliphant "Python for Speed, Scale, and Science"
Travis Oliphant "Python for Speed, Scale, and Science"Travis Oliphant "Python for Speed, Scale, and Science"
Travis Oliphant "Python for Speed, Scale, and Science"Fwdays
 
Get started with Lua - Hackference 2016
Get started with Lua - Hackference 2016Get started with Lua - Hackference 2016
Get started with Lua - Hackference 2016Etiene Dalcol
 
A Hands-on Intro to Data Science and R Presentation.ppt
A Hands-on Intro to Data Science and R Presentation.pptA Hands-on Intro to Data Science and R Presentation.ppt
A Hands-on Intro to Data Science and R Presentation.pptSanket Shikhar
 
A Workshop on R
A Workshop on RA Workshop on R
A Workshop on RAjay Ohri
 
Matplotlib adalah pustaka plotting 2D Python yang menghasilkan gambar berkual...
Matplotlib adalah pustaka plotting 2D Python yang menghasilkan gambar berkual...Matplotlib adalah pustaka plotting 2D Python yang menghasilkan gambar berkual...
Matplotlib adalah pustaka plotting 2D Python yang menghasilkan gambar berkual...HendraPurnama31
 
Standardizing on a single N-dimensional array API for Python
Standardizing on a single N-dimensional array API for PythonStandardizing on a single N-dimensional array API for Python
Standardizing on a single N-dimensional array API for PythonRalf Gommers
 
Python高级编程(二)
Python高级编程(二)Python高级编程(二)
Python高级编程(二)Qiangning Hong
 
Python and Oracle : allies for best of data management
Python and Oracle : allies for best of data managementPython and Oracle : allies for best of data management
Python and Oracle : allies for best of data managementLaurent Leturgez
 
python-numpyandpandas-170922144956 (1).pptx
python-numpyandpandas-170922144956 (1).pptxpython-numpyandpandas-170922144956 (1).pptx
python-numpyandpandas-170922144956 (1).pptxAkashgupta517936
 
¡El mejor lenguaje para automatizar pruebas!
¡El mejor lenguaje para automatizar pruebas!¡El mejor lenguaje para automatizar pruebas!
¡El mejor lenguaje para automatizar pruebas!Antonio Robres Turon
 
State of Play. Data Science on Hadoop in 2015 by SEAN OWEN at Big Data Spain ...
State of Play. Data Science on Hadoop in 2015 by SEAN OWEN at Big Data Spain ...State of Play. Data Science on Hadoop in 2015 by SEAN OWEN at Big Data Spain ...
State of Play. Data Science on Hadoop in 2015 by SEAN OWEN at Big Data Spain ...Big Data Spain
 
NOSQL101, Or: How I Learned To Stop Worrying And Love The Mongo!
NOSQL101, Or: How I Learned To Stop Worrying And Love The Mongo!NOSQL101, Or: How I Learned To Stop Worrying And Love The Mongo!
NOSQL101, Or: How I Learned To Stop Worrying And Love The Mongo!Daniel Cousineau
 
Fast and Scalable Python
Fast and Scalable PythonFast and Scalable Python
Fast and Scalable PythonTravis Oliphant
 

Semelhante a Migrating from matlab to python (20)

AI與大數據數據處理 Spark實戰(20171216)
AI與大數據數據處理 Spark實戰(20171216)AI與大數據數據處理 Spark實戰(20171216)
AI與大數據數據處理 Spark實戰(20171216)
 
Travis Oliphant "Python for Speed, Scale, and Science"
Travis Oliphant "Python for Speed, Scale, and Science"Travis Oliphant "Python for Speed, Scale, and Science"
Travis Oliphant "Python for Speed, Scale, and Science"
 
Ch1
Ch1Ch1
Ch1
 
Get started with Lua - Hackference 2016
Get started with Lua - Hackference 2016Get started with Lua - Hackference 2016
Get started with Lua - Hackference 2016
 
A Hands-on Intro to Data Science and R Presentation.ppt
A Hands-on Intro to Data Science and R Presentation.pptA Hands-on Intro to Data Science and R Presentation.ppt
A Hands-on Intro to Data Science and R Presentation.ppt
 
Python: The Dynamic!
Python: The Dynamic!Python: The Dynamic!
Python: The Dynamic!
 
A Workshop on R
A Workshop on RA Workshop on R
A Workshop on R
 
Matplotlib adalah pustaka plotting 2D Python yang menghasilkan gambar berkual...
Matplotlib adalah pustaka plotting 2D Python yang menghasilkan gambar berkual...Matplotlib adalah pustaka plotting 2D Python yang menghasilkan gambar berkual...
Matplotlib adalah pustaka plotting 2D Python yang menghasilkan gambar berkual...
 
04 standard class library c#
04 standard class library c#04 standard class library c#
04 standard class library c#
 
Standardizing on a single N-dimensional array API for Python
Standardizing on a single N-dimensional array API for PythonStandardizing on a single N-dimensional array API for Python
Standardizing on a single N-dimensional array API for Python
 
Python高级编程(二)
Python高级编程(二)Python高级编程(二)
Python高级编程(二)
 
R programmingmilano
R programmingmilanoR programmingmilano
R programmingmilano
 
Python and Oracle : allies for best of data management
Python and Oracle : allies for best of data managementPython and Oracle : allies for best of data management
Python and Oracle : allies for best of data management
 
Python.pptx
Python.pptxPython.pptx
Python.pptx
 
python-numpyandpandas-170922144956 (1).pptx
python-numpyandpandas-170922144956 (1).pptxpython-numpyandpandas-170922144956 (1).pptx
python-numpyandpandas-170922144956 (1).pptx
 
¡El mejor lenguaje para automatizar pruebas!
¡El mejor lenguaje para automatizar pruebas!¡El mejor lenguaje para automatizar pruebas!
¡El mejor lenguaje para automatizar pruebas!
 
State of Play. Data Science on Hadoop in 2015 by SEAN OWEN at Big Data Spain ...
State of Play. Data Science on Hadoop in 2015 by SEAN OWEN at Big Data Spain ...State of Play. Data Science on Hadoop in 2015 by SEAN OWEN at Big Data Spain ...
State of Play. Data Science on Hadoop in 2015 by SEAN OWEN at Big Data Spain ...
 
NOSQL101, Or: How I Learned To Stop Worrying And Love The Mongo!
NOSQL101, Or: How I Learned To Stop Worrying And Love The Mongo!NOSQL101, Or: How I Learned To Stop Worrying And Love The Mongo!
NOSQL101, Or: How I Learned To Stop Worrying And Love The Mongo!
 
Fast and Scalable Python
Fast and Scalable PythonFast and Scalable Python
Fast and Scalable Python
 
Session 2
Session 2Session 2
Session 2
 

Mais de ActiveState

Robust Algorithms for Machine Learning
Robust Algorithms for Machine LearningRobust Algorithms for Machine Learning
Robust Algorithms for Machine LearningActiveState
 
ActiveState - The Open Source Languages Company
ActiveState - The Open Source Languages CompanyActiveState - The Open Source Languages Company
ActiveState - The Open Source Languages CompanyActiveState
 
ActiveState Open Source Survey - 2016
ActiveState Open Source Survey - 2016ActiveState Open Source Survey - 2016
ActiveState Open Source Survey - 2016ActiveState
 
ActiveState Tcl Survey - 2016
ActiveState Tcl Survey - 2016ActiveState Tcl Survey - 2016
ActiveState Tcl Survey - 2016ActiveState
 
Practical LPeg - Lua Workshop 2016
Practical LPeg - Lua Workshop 2016Practical LPeg - Lua Workshop 2016
Practical LPeg - Lua Workshop 2016ActiveState
 
Overview of Komodo IDE 10.1
Overview of Komodo IDE 10.1Overview of Komodo IDE 10.1
Overview of Komodo IDE 10.1ActiveState
 
The ActiveState of Tcl
The ActiveState of TclThe ActiveState of Tcl
The ActiveState of TclActiveState
 
PERL SURVEY 2016
PERL SURVEY 2016PERL SURVEY 2016
PERL SURVEY 2016ActiveState
 
Improving Customer Experience Using ActivePerl and ActivePython
Improving Customer Experience Using ActivePerl and ActivePythonImproving Customer Experience Using ActivePerl and ActivePython
Improving Customer Experience Using ActivePerl and ActivePythonActiveState
 
Python: The Programmer's Lingua Franca
Python: The Programmer's Lingua FrancaPython: The Programmer's Lingua Franca
Python: The Programmer's Lingua FrancaActiveState
 
Continuing Evolution of Perl: Highlights of ActivePerl 5.14
Continuing Evolution of Perl: Highlights of ActivePerl 5.14Continuing Evolution of Perl: Highlights of ActivePerl 5.14
Continuing Evolution of Perl: Highlights of ActivePerl 5.14ActiveState
 
Looking Ahead to Tcl 8.6
Looking Ahead to Tcl 8.6Looking Ahead to Tcl 8.6
Looking Ahead to Tcl 8.6ActiveState
 
US SEC Mandates, Python, and Financial Modeling
US SEC Mandates, Python, and Financial ModelingUS SEC Mandates, Python, and Financial Modeling
US SEC Mandates, Python, and Financial ModelingActiveState
 
ActiveState, CA, Taking quality products to market faster with enterprise rea...
ActiveState, CA, Taking quality products to market faster with enterprise rea...ActiveState, CA, Taking quality products to market faster with enterprise rea...
ActiveState, CA, Taking quality products to market faster with enterprise rea...ActiveState
 
Keeping up with Perl: Development, Upgrade and Deployment Options for Perl 5.12
Keeping up with Perl: Development, Upgrade and Deployment Options for Perl 5.12Keeping up with Perl: Development, Upgrade and Deployment Options for Perl 5.12
Keeping up with Perl: Development, Upgrade and Deployment Options for Perl 5.12ActiveState
 
Python & Finance: US Government Mandates, Financial Modeling, and Other Snake...
Python & Finance: US Government Mandates, Financial Modeling, and Other Snake...Python & Finance: US Government Mandates, Financial Modeling, and Other Snake...
Python & Finance: US Government Mandates, Financial Modeling, and Other Snake...ActiveState
 
Best Practices in Porting & Developing Enterprise Applications to the Cloud u...
Best Practices in Porting & Developing Enterprise Applications to the Cloud u...Best Practices in Porting & Developing Enterprise Applications to the Cloud u...
Best Practices in Porting & Developing Enterprise Applications to the Cloud u...ActiveState
 
Safeguarding Against the Risks of Improper Open Source Licensing - Valuable...
Safeguarding Against the Risks of Improper Open Source Licensing - Valuable...Safeguarding Against the Risks of Improper Open Source Licensing - Valuable...
Safeguarding Against the Risks of Improper Open Source Licensing - Valuable...ActiveState
 
Take Quality Products to Market Faster with Enterprise-Ready Dynamic Languages
Take Quality Products to Market Faster with Enterprise-Ready Dynamic LanguagesTake Quality Products to Market Faster with Enterprise-Ready Dynamic Languages
Take Quality Products to Market Faster with Enterprise-Ready Dynamic LanguagesActiveState
 

Mais de ActiveState (20)

Robust Algorithms for Machine Learning
Robust Algorithms for Machine LearningRobust Algorithms for Machine Learning
Robust Algorithms for Machine Learning
 
TDD Pros & Cons
TDD Pros & ConsTDD Pros & Cons
TDD Pros & Cons
 
ActiveState - The Open Source Languages Company
ActiveState - The Open Source Languages CompanyActiveState - The Open Source Languages Company
ActiveState - The Open Source Languages Company
 
ActiveState Open Source Survey - 2016
ActiveState Open Source Survey - 2016ActiveState Open Source Survey - 2016
ActiveState Open Source Survey - 2016
 
ActiveState Tcl Survey - 2016
ActiveState Tcl Survey - 2016ActiveState Tcl Survey - 2016
ActiveState Tcl Survey - 2016
 
Practical LPeg - Lua Workshop 2016
Practical LPeg - Lua Workshop 2016Practical LPeg - Lua Workshop 2016
Practical LPeg - Lua Workshop 2016
 
Overview of Komodo IDE 10.1
Overview of Komodo IDE 10.1Overview of Komodo IDE 10.1
Overview of Komodo IDE 10.1
 
The ActiveState of Tcl
The ActiveState of TclThe ActiveState of Tcl
The ActiveState of Tcl
 
PERL SURVEY 2016
PERL SURVEY 2016PERL SURVEY 2016
PERL SURVEY 2016
 
Improving Customer Experience Using ActivePerl and ActivePython
Improving Customer Experience Using ActivePerl and ActivePythonImproving Customer Experience Using ActivePerl and ActivePython
Improving Customer Experience Using ActivePerl and ActivePython
 
Python: The Programmer's Lingua Franca
Python: The Programmer's Lingua FrancaPython: The Programmer's Lingua Franca
Python: The Programmer's Lingua Franca
 
Continuing Evolution of Perl: Highlights of ActivePerl 5.14
Continuing Evolution of Perl: Highlights of ActivePerl 5.14Continuing Evolution of Perl: Highlights of ActivePerl 5.14
Continuing Evolution of Perl: Highlights of ActivePerl 5.14
 
Looking Ahead to Tcl 8.6
Looking Ahead to Tcl 8.6Looking Ahead to Tcl 8.6
Looking Ahead to Tcl 8.6
 
US SEC Mandates, Python, and Financial Modeling
US SEC Mandates, Python, and Financial ModelingUS SEC Mandates, Python, and Financial Modeling
US SEC Mandates, Python, and Financial Modeling
 
ActiveState, CA, Taking quality products to market faster with enterprise rea...
ActiveState, CA, Taking quality products to market faster with enterprise rea...ActiveState, CA, Taking quality products to market faster with enterprise rea...
ActiveState, CA, Taking quality products to market faster with enterprise rea...
 
Keeping up with Perl: Development, Upgrade and Deployment Options for Perl 5.12
Keeping up with Perl: Development, Upgrade and Deployment Options for Perl 5.12Keeping up with Perl: Development, Upgrade and Deployment Options for Perl 5.12
Keeping up with Perl: Development, Upgrade and Deployment Options for Perl 5.12
 
Python & Finance: US Government Mandates, Financial Modeling, and Other Snake...
Python & Finance: US Government Mandates, Financial Modeling, and Other Snake...Python & Finance: US Government Mandates, Financial Modeling, and Other Snake...
Python & Finance: US Government Mandates, Financial Modeling, and Other Snake...
 
Best Practices in Porting & Developing Enterprise Applications to the Cloud u...
Best Practices in Porting & Developing Enterprise Applications to the Cloud u...Best Practices in Porting & Developing Enterprise Applications to the Cloud u...
Best Practices in Porting & Developing Enterprise Applications to the Cloud u...
 
Safeguarding Against the Risks of Improper Open Source Licensing - Valuable...
Safeguarding Against the Risks of Improper Open Source Licensing - Valuable...Safeguarding Against the Risks of Improper Open Source Licensing - Valuable...
Safeguarding Against the Risks of Improper Open Source Licensing - Valuable...
 
Take Quality Products to Market Faster with Enterprise-Ready Dynamic Languages
Take Quality Products to Market Faster with Enterprise-Ready Dynamic LanguagesTake Quality Products to Market Faster with Enterprise-Ready Dynamic 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
  • 7. Packages Include • "Pylab": NumPy, SciPy, Matplotlib • GUI Toolkits: pyQT, wxPython • Database Connectors: Postgres, MySQL, Oracle, MSSQL, SqlAlchemy, ODBC • Cryptography: M2Crypto
  • 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
  • 25. Create Arrays >>> import numpy as np >>> a = np.array([[1, 2, 3], [4, 5, 6]]) >>> a array([[1, 2, 3], [4, 5, 6]]) >>> a.shape (2, 3) >>> a.dtype dtype('int32') >>> a.size 6
  • 26. Create Arrays >>> b = np.arange(10) >>> b array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) >>> c = np.array([[1, 2, 3], [4, 5, 6]], dtype=np.float32) >>> c array([[ 1., 2., 3.], [ 4., 5., 6.]], dtype=float32)
  • 27. Create Arrays >>> np.arange(16, dtype=np.float).reshape(4, 4) array([[ 0., 1., 2., 3.], [ 4., 5., 6., 7.], [ 8., 9., 10., 11.], [ 12., 13., 14., 15.]]) >>> np.zeros((3, 4)) array([[ 0., 0., 0., 0.], [ 0., 0., 0., 0.], [ 0., 0., 0., 0.]])
  • 28. Create Arrays >>> np.ones((3, 4)) array([[ 1., 1., 1., 1.], [ 1., 1., 1., 1.], [ 1., 1., 1., 1.]]) >>> np.zeros((3, 4)) + 5 array([[ 5., 5., 5., 5.], [ 5., 5., 5., 5.], [ 5., 5., 5., 5.]])
  • 29. Data Types • 21 data types • signed and unsigned integer (8, 16, 32, 64 bit) • floats (32, 64 an 96 bit) • complex (64, 128, 192 bit) • bool • string • character • objects
  • 30. Data Types >>> a = np.array([1, 2, 3], dtype=np.int64) >>> a array([1, 2, 3], dtype=int64) >>> a.dtype dtype('int64') >>> a.dtype.type <type 'numpy.int64'> >>> a.dtype.char 'q' >>> a.dtype.str '<i8'
  • 31. Slicing >>> one_d = np.arange(10) >>> one_d array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) >>> one_d[0] 0 >>> one_d[1] 1 >>> one_d[-1] 9 >>> one_d[2:5] array([2, 3, 4])
  • 32. Slicing >>> two_d = np.arange(25).reshape(5, 5) >>> two_d array([[ 0, 1, 2, 3, 4], [ 5, 6, 7, 8, 9], [10, 11, 12, 13, 14], [15, 16, 17, 18, 19], [20, 21, 22, 23, 24]]) >>> two_d[0, 0] 0 >>> two_d[0] array([0, 1, 2, 3, 4])
  • 33. Slicing >>> two_d[:,0] array([ 0, 5, 10, 15, 20]) >>> two_d[1:-1,1:-1] array([[ 6, 7, 8], [11, 12, 13], [16, 17, 18]]) • advanced selection (integers, booleans, strings) • "loop-less" programming
  • 34. Broadcasting >>> two_d array([[ 0, 1, 2, 3, 4], [ 5, 6, 7, 8, 9], [10, 11, 12, 13, 14], [15, 16, 17, 18, 19], [20, 21, 22, 23, 24]]) >>> two_d + 5 array([[ 5, 6, 7, 8, 9], [10, 11, 12, 13, 14], [15, 16, 17, 18, 19], [20, 21, 22, 23, 24], [25, 26, 27, 28, 29]])
  • 35. Broadcasting >>> a = np.arange(8).reshape(2, 4) >>> a array([[0, 1, 2, 3], [4, 5, 6, 7]]) >>> b = np.arange(4) >>> b array([0, 1, 2, 3]) >>> a + b array([[ 0, 2, 4, 6], [ 4, 6, 8, 10]])
  • 36. Universal Functions >>> np.sin(a) array([[ 0. , 0.84147098, 0.90929743, 0.14112001], [-0.7568025 , -0.95892427, -0.2794155 , 0.6569866 ]]) >>> np.sin.nin 1 >>> np.sin.nout 1 >>> np.sin.types ['f->f', 'd->d', 'g->g', 'F->F', 'D->D', 'G->G', 'O->O']
  • 37. Matrices • always 2D >>> M = np.matrix('1 2 3; 4 5 6') >>> M matrix([[1, 2, 3], [4, 5, 6]]) >>> M.I matrix([[-0.94444444, 0.44444444], [-0.11111111, 0.11111111], [ 0.72222222, -0.22222222]])
  • 38. SciPy • big package • interpolation • linear algebra • FFT • statistics • optimization • much more
  • 39. IPython • improved interactive shell • object introspection • system shell access • command system for adding functionality • allows interactive work with matplotlib ipython -pylab
  • 40. Basic matplotlib-plotting • simple, yet powerful plotting package In [1]: plot(random(100)) Out[1]: [<matplotlib.lines.Line2D object at 0x02A3EA90>]
  • 41. Properties • colors • line styles • markers • legend
  • 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
  • 53. Performance and Future Developments • multi-cores • multiprocessing (standard library) • GPUs • theano • pyCUDA • Clyther
  • 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
  • 57. We've Got Your Universe Covered