SlideShare a Scribd company logo
1 of 46
Download to read offline
Why Python?                            Introduction to Python                                    Further Info




                   Scientific Programming in Python


                                      Eric Christiansen
                                            UCSD CSE




                                    September 16, 2008




              This work is licensed under the Creative Commons Attribution 3.0 License.

                            Based on a MATLAB tutorial by Tim Marks


                                                                       Scientific Programming in Python
                                                                                                         1 / 22
Why Python?                    Introduction to Python                             Further Info


                          What is Python?



     Python in a very high level (scripting) language which has gained
     widespread popularity in recent years.
     It is:




                                                        Scientific Programming in Python
                                                                                          2 / 22
Why Python?                       Introduction to Python                             Further Info


                               What is Python?



     Python in a very high level (scripting) language which has gained
     widespread popularity in recent years.
     It is:
              cross platform




                                                           Scientific Programming in Python
                                                                                             2 / 22
Why Python?                        Introduction to Python                             Further Info


                                What is Python?



     Python in a very high level (scripting) language which has gained
     widespread popularity in recent years.
     It is:
              cross platform
              object oriented




                                                            Scientific Programming in Python
                                                                                              2 / 22
Why Python?                        Introduction to Python                             Further Info


                                What is Python?



     Python in a very high level (scripting) language which has gained
     widespread popularity in recent years.
     It is:
              cross platform
              object oriented
              open source




                                                            Scientific Programming in Python
                                                                                              2 / 22
Why Python?       Introduction to Python                             Further Info


              Why should I care?




                                           Scientific Programming in Python
                                                                             3 / 22
Why Python?                         Introduction to Python                             Further Info


                                Why should I care?



     You may need to use a computer to
              run simulations
              crunch data
              display data...




                                                             Scientific Programming in Python
                                                                                               3 / 22
Why Python?                         Introduction to Python                             Further Info


                                Why should I care?



     You may need to use a computer to
              run simulations
              crunch data
              display data...
     Python’s 3rd -party libraries can help you with these tasks.




                                                             Scientific Programming in Python
                                                                                               3 / 22
Why Python?                     Introduction to Python                             Further Info


                   Python’s Scientific Libraries



     Python is enhanced by a large set of scientific libraries that are
     being actively developed.




                                                         Scientific Programming in Python
                                                                                           4 / 22
Why Python?                           Introduction to Python                             Further Info


                       Python’s Scientific Libraries



     Python is enhanced by a large set of scientific libraries that are
     being actively developed.
              standard science and engineering functions or plotting (MATLAB)
                  SciPy, Matplotlib




                                                               Scientific Programming in Python
                                                                                                 4 / 22
Why Python?                           Introduction to Python                             Further Info


                       Python’s Scientific Libraries



     Python is enhanced by a large set of scientific libraries that are
     being actively developed.
              standard science and engineering functions or plotting (MATLAB)
                  SciPy, Matplotlib
              a computer algebra system (Mathematica)
                  SAGE




                                                               Scientific Programming in Python
                                                                                                 4 / 22
Why Python?            Introduction to Python                             Further Info


              Python’s Scientific Libraries




                                                Scientific Programming in Python
                                                                                  5 / 22
Why Python?                           Introduction to Python                             Further Info


                       Python’s Scientific Libraries

              data processing
                   Modular toolkit for Data Processing (MDP)




                                                               Scientific Programming in Python
                                                                                                 5 / 22
Why Python?                              Introduction to Python                             Further Info


                       Python’s Scientific Libraries

              data processing
                   Modular toolkit for Data Processing (MDP)
              bioinformatics functions
                   Biopython




                                                                  Scientific Programming in Python
                                                                                                    5 / 22
Why Python?                              Introduction to Python                             Further Info


                       Python’s Scientific Libraries

              data processing
                   Modular toolkit for Data Processing (MDP)
              bioinformatics functions
                   Biopython
              machine learning functions
                   PyML, mlpy, SHOGUN




                                                                  Scientific Programming in Python
                                                                                                    5 / 22
Why Python?                              Introduction to Python                             Further Info


                       Python’s Scientific Libraries

              data processing
                   Modular toolkit for Data Processing (MDP)
              bioinformatics functions
                   Biopython
              machine learning functions
                   PyML, mlpy, SHOGUN
              neural nets
                   Fast Artificial Neural Network (FANN) Library




                                                                  Scientific Programming in Python
                                                                                                    5 / 22
Why Python?                              Introduction to Python                             Further Info


                        Python’s Scientific Libraries

              data processing
                   Modular toolkit for Data Processing (MDP)
              bioinformatics functions
                   Biopython
              machine learning functions
                   PyML, mlpy, SHOGUN
              neural nets
                   Fast Artificial Neural Network (FANN) Library
              artificial intelligence or robotics routines
                   Python Robotics (Pyro)



                                                                  Scientific Programming in Python
                                                                                                    5 / 22
Why Python?        Introduction to Python                             Further Info


              Is it hard to learn?




                                            Scientific Programming in Python
                                                                              6 / 22
Why Python?        Introduction to Python                             Further Info


              Is it hard to learn?




                                            Scientific Programming in Python
                                                                              6 / 22
Why Python?                  Introduction to Python                             Further Info


                    Python vs MATLAB

     Advantages of MATLAB:




                                                      Scientific Programming in Python
                                                                                        7 / 22
Why Python?                         Introduction to Python                             Further Info


                             Python vs MATLAB

     Advantages of MATLAB:
              already widely used




                                                             Scientific Programming in Python
                                                                                               7 / 22
Why Python?                           Introduction to Python                             Further Info


                             Python vs MATLAB

     Advantages of MATLAB:
              already widely used
              designed specifically for scientific computing




                                                               Scientific Programming in Python
                                                                                                 7 / 22
Why Python?                           Introduction to Python                             Further Info


                             Python vs MATLAB

     Advantages of MATLAB:
              already widely used
              designed specifically for scientific computing
              easy to find documentation




                                                               Scientific Programming in Python
                                                                                                 7 / 22
Why Python?                           Introduction to Python                             Further Info


                             Python vs MATLAB

     Advantages of MATLAB:
              already widely used
              designed specifically for scientific computing
              easy to find documentation
              good IDE with debugging and profiling support “out of the box”




                                                               Scientific Programming in Python
                                                                                                 7 / 22
Why Python?                           Introduction to Python                             Further Info


                             Python vs MATLAB

     Advantages of MATLAB:
              already widely used
              designed specifically for scientific computing
              easy to find documentation
              good IDE with debugging and profiling support “out of the box”
     Advantages of Python:




                                                               Scientific Programming in Python
                                                                                                 7 / 22
Why Python?                           Introduction to Python                             Further Info


                             Python vs MATLAB

     Advantages of MATLAB:
              already widely used
              designed specifically for scientific computing
              easy to find documentation
              good IDE with debugging and profiling support “out of the box”
     Advantages of Python:
              open source means no limits on use




                                                               Scientific Programming in Python
                                                                                                 7 / 22
Why Python?                           Introduction to Python                             Further Info


                             Python vs MATLAB

     Advantages of MATLAB:
              already widely used
              designed specifically for scientific computing
              easy to find documentation
              good IDE with debugging and profiling support “out of the box”
     Advantages of Python:
              open source means no limits on use
              appears to approximately superset MATLAB’s functionality




                                                               Scientific Programming in Python
                                                                                                 7 / 22
Why Python?                           Introduction to Python                             Further Info


                             Python vs MATLAB

     Advantages of MATLAB:
              already widely used
              designed specifically for scientific computing
              easy to find documentation
              good IDE with debugging and profiling support “out of the box”
     Advantages of Python:
              open source means no limits on use
              appears to approximately superset MATLAB’s functionality
              modern language with support for object orientation




                                                               Scientific Programming in Python
                                                                                                 7 / 22
Why Python?                           Introduction to Python                             Further Info


                             Python vs MATLAB

     Advantages of MATLAB:
              already widely used
              designed specifically for scientific computing
              easy to find documentation
              good IDE with debugging and profiling support “out of the box”
     Advantages of Python:
              open source means no limits on use
              appears to approximately superset MATLAB’s functionality
              modern language with support for object orientation
              support for calling functions in other languages


                                                               Scientific Programming in Python
                                                                                                 7 / 22
Why Python?                         Introduction to Python                             Further Info


                                       Basics
     To get information on an object from the interpreter
     h e l p <o b j e c t >
     Commenting:
              Inline comments are preceded with #
              Block comments are surrounded with ”””
     Code blocks are denoted with indentation:
     i f x == 2 :
          print x
     Python is dynamically typed:
     a = ”hello” # a is a string
     a = 4       # a i s now an i n t e g e r


                                                             Scientific Programming in Python
                                                                                               8 / 22
Why Python?                                  Introduction to Python                              Further Info


                                               Vectors
     Many of these functions come from SciPy.
     from s c i p y import ∗
     Vectors:
     N   =    5                                      #   a scalar
     v   =    [1 ,2 ,3]                              #   a list
     v   =    array ([1 ,2 ,3])                      #   a column v e c t o r
     v   =    a r r a y ( [ [ 1 ] , [ 2 ] , [ 3 ] ] )#   a column v e c t o r
     v   =    array ([[1 ,2 ,3]])                    #   a column v e c t o r
     v   =    transpose (v)                          #   transpose a vector
                                                     #   ( row t o column
                                                     #   o r column t o row )
     v =      a r a n g e ( −4 ,4)                   #   a vector in
                                                     #   a s p e c i f i e d range :
     v =      p i ∗ a r a n g e ( −4 ,4)/4
     v =      arange ( −4 ,4 ,.5)                    #   arange ( s t a r t , stop , s t e p )
     v =      []                                     #   empty l i s t
                                                                       Scientific Programming in Python
                                                                                                         9 / 22
Why Python?                   Introduction to Python                             Further Info


                              Matrices



     v = array ([5 ,6 ,7])    #    access a vector element
     v [2]                    #    vector ( index ) − arrays are
                              #    z e r o −i n d e x e d
    len (v)                   #    number o f e l e m e n t s i n a v e c t o r
    m = array ([[1 ,2 ,3] ,
           [4 ,5 ,6]])          # a 2 x3 m a t r i x
    m[ 1 , 2 ] == m [ 1 ] [ 2 ] # access a matrix element
                                # m a t r i x [ row , column ]




                                                       Scientific Programming in Python
                                                                                         10 / 22
Why Python?                             Introduction to Python                             Further Info


                      Syntax and Special Functions




     Matrices:
    m   =     zeros ([2 ,3])       #   a matrix of zeros
    v   =     ones ( [ 1 , 3 ] )   #   a matrix of ones
    v   =     rand (3 ,1)          #   rand matrix ( see a l s o randn )
    m   =     eye (3)              #   i d e n t i t y m a t r i x ( 3 x3 )




                                                                 Scientific Programming in Python
                                                                                                   11 / 22
Why Python?                              Introduction to Python                             Further Info


              Syntax and Special Functions (cont)

    m[ 1 , : ]                       #   a c c e s s a m a t r i x row ( s e c o n d row )
    m[ : , 0 ]                       #   a c c e s s a m a t r i x column ( l e f t column )
    m[ 1 : , 1 : ]                   #   lower r i g h t submatrix
    m. r e s h a p e ( [ 4 , 1 ] )   #   t u r n m a t r i x i n t o a column
                                     #   v e c t o r ( c o n c a t e n a t e rows )
    m. s h a p e                     #   s i z e o f a m a t r i x [ rows , c o l s ]
    m. s h a p e [ 0 ]               #   number o f rows
    m. s h a p e [ 1 ]               #   number o f c o l u m n s
    z e r o s (m. s h a p e )        #   c r e a t e a new m a t r i x w i t h
                                     #   s i z e of m

    m = a r r a y ( [ [ ’ h e l l o ’ , sum ] , 
           [1 ,2]])                # p u t w h a t e v e r you want
                                   # i n t o an a r r a y
    m[ 0 , 1 ] (m[ 1 ] )           # c a l l sum on bottom row o f m

                                                                  Scientific Programming in Python
                                                                                                    12 / 22
Why Python?                               Introduction to Python                             Further Info


              Syntax and Special Functions (cont)
     Arithmetic operations performed on arrays are done “element by
     element”.
     a = array ([1 ,2 ,3 ,4])             #    vector
     2 ∗ a                                #    scalar multiplication
     a / 4                                #    scalar division
     b = array ([5 ,6 ,7 ,8])             #    vector
     a + b                                #    pointwise vector addition
     a − b                                #    pointwise vector subtraction
     a ∗∗ 2                               #    pointise vector squaring
     a ∗ b                                #    pointwise vector multiply
     a / b                                #    pointwise vector divide
     log (a)                              #    pointwise logarithm
     around ( a r r a y ( [ [ . 6 ] , 
          [.5]]))                         # pointwise rounding
                                          # ( . 5 rounds to 0)

                                                                   Scientific Programming in Python
                                                                                                     13 / 22
Why Python?                     Introduction to Python                              Further Info


                       Vector Operations

     a = array ([1 ,4 ,6 ,3])   #    vector
     sum ( a )                  #    sum o f v e c t o r e l e m e n t s
     mean ( a )                 #    mean o f v e c t o r e l e m e n t s
     var (a)                    #    variance
     std (a)                    #    standard deviation
     max ( a )                  #    maximum

     a = array ([[1 ,2 ,3] ,
          [4 ,5 ,6]])           #    matrix
     mean ( a , 0 )             #    mean o f e a c h column
     amax ( a , 1 )             #    max o f e a c h row
     amax ( a )                 #    t o o b t a i n max o f m a t r i x
                                #    n o t e we u s e 2
                                #    d i f f e r e n t max f u n c t i o n s


                                                          Scientific Programming in Python
                                                                                            14 / 22
Why Python?                           Introduction to Python                             Further Info


                              Matrix Operations

     dot ( t r a n s p o s e ( a r r a y ( [ 1 , 2 , 3 ] ) ) , 
           array ([4 ,5 ,6]))                  # row v e c t o r 1 x3 t i m e s column
                                               # v e c t o r 3 x1 r e s u l t s i n a
                                               # s i n g l e number , a l s o known
                                               # as dot / i n n e r product
     dot ( a r r a y ( [ [ 1 ] , [ 2 ] , [ 3 ] ] ) , 
           a r r a y ( [ [ 4 , 5 , 6 ] ] ) ) # column v e c t o r 3 x1 t i m e s row
                                               # v e c t o r 1 x3 r e s u l t s i n 3 x3
                                               # m a t r i x , a l s o known
                                               # as outer product
     a = rand (3 ,2)                           # 3 x2 m a t r i x
     b = rand (2 ,4)                           # 2 x4 m a t r i x
     dot ( a , b )                             # 3 x4 m a t r i x



                                                               Scientific Programming in Python
                                                                                                 15 / 22
Why Python?                         Introduction to Python                               Further Info


                            Saving Your Work

     import c P i c k l e a s p i c k l e      # t h i s module l e t s you
                                               # s a v e and r e l o a d o b j e c t s

     f = open ( ’ s a v e f i l e ’ , ’w ’ ) # open a r c h i v e f i l e
     p i c k l e . dump ( o b j , f )        # dump o b j e c t t o a r c h i v e
     f . close ()                            # close archive f i l e

     del obj                                   # clear object
                                               # from memory

     f = open ( ’ s a v e f i l e ’ , ’ r ’ ) # open         archive f i l e
     obj = p i c k l e . load ( f )           # read         object
                                              # from         archive
     f . close ()                             # close         archive f i l e


                                                               Scientific Programming in Python
                                                                                                 16 / 22
Why Python?                      Introduction to Python                             Further Info


                        Relations and Control

     Example: given a list v, create a new list u with values equal to v if
     they are greater than 0, and equal to 0 if they less than or equal to
     0.
     Using a for loop:
     v = [3 ,5 , −2 ,5 , −1 ,0]
     u = [0] ∗ len (v) # u is a l l zeros
     for i in range ( len ( v ) ) :
         i f v [ i ] > 0:
               u[ i ] = v[ i ]
     Using list comprehension:
     v = [3 ,5 , −2 ,5 , −1 ,0]
     u = [ max ( e , 0 ) f o r e i n v ]



                                                          Scientific Programming in Python
                                                                                            17 / 22
Why Python?                     Introduction to Python                             Further Info


                        Importing Functions
     Save the following code to “mylib.py”:
     def myfunc ( a , b ) :
         r e t u r n a+b ∗∗2
     Import and use myfunc. Note, we might need to configure
     PYTHONPATH.
     from m y l i b import myfunc
     myfunc ( 1 , 2 )
     myfunc ( b=2, a=1) # same a s a bo v e
     Python also supports class creation:
     c l a s s MyClass :
             def    init ( self ):
                  print ” hello ! ”
     m y c l a s s = MyClass ( )

                                                         Scientific Programming in Python
                                                                                           18 / 22
Why Python?                       Introduction to Python                             Further Info


                                      Plotting




     The library matplotlib / pylab is your friend:
     from p y l a b import ∗
     xs = arange ( −2 ,2 ,.01)
     p l o t ( xs , s i n ( x s ) )
     show ( )




                                                           Scientific Programming in Python
                                                                                             19 / 22
Why Python?                          Introduction to Python                             Further Info


                                      Imaging
     We use the Python Imaging Library as well as matplotlib / pylab.
     from p y l a b import ∗
     import Image

     im = Image . open ( ’ my image . j p g ’ )
     im . show ( )                        # we can d i s p l a y t h e image
     ima = a r r a y ( im )               # t y p e c a s t i n g to a r r a y
                                          # extracts pixel values
     i m r = Image . f r o m s t r i n g ( ’RGB ’ , 
           ( ima . s h a p e [ 1 ] , ima . s h a p e [ 0 ] ) , 
           ima . t o s t r i n g ( ) )    # c o n v e r t a r r a y i n t o image
     img = mean ( ima , 2 )               # average color i n t e n s i t i e s
                                          # f o r each p i x e l
     imshow ( img )
     autumn ( )                           # s e t d e f a u l t c o l o r m a p t o autumn
     show ( )

                                                              Scientific Programming in Python
                                                                                                20 / 22
Why Python?                     Introduction to Python                             Further Info


                              More Help?




     Many guides and tutorials are available online:




                                                         Scientific Programming in Python
                                                                                           21 / 22
Why Python?                         Introduction to Python                             Further Info


                                   More Help?




     Many guides and tutorials are available online:
     Dive Into Python
              python introduction for programmers




                                                             Scientific Programming in Python
                                                                                               21 / 22
Why Python?                         Introduction to Python                             Further Info


                                   More Help?




     Many guides and tutorials are available online:
     Dive Into Python
              python introduction for programmers
     A list of tutorials for Python and some of its many libraries can be
     found at http://www.awaretek.com/tutorials.html




                                                             Scientific Programming in Python
                                                                                               21 / 22
Why Python?   Introduction to Python                             Further Info




               Questions?




                                       Scientific Programming in Python
                                                                         22 / 22

More Related Content

What's hot

pycon-2015-liza-daly
pycon-2015-liza-dalypycon-2015-liza-daly
pycon-2015-liza-dalyLiza Daly
 
summer training report on python
summer training report on pythonsummer training report on python
summer training report on pythonShubham Yadav
 
Chapter 8 getting started with python
Chapter 8 getting started with pythonChapter 8 getting started with python
Chapter 8 getting started with pythonPraveen M Jigajinni
 
Machine Learning empowered by Python April2009
Machine Learning empowered by Python April2009Machine Learning empowered by Python April2009
Machine Learning empowered by Python April2009Francis Piéraut
 
Python for Science and Engineering: a presentation to A*STAR and the Singapor...
Python for Science and Engineering: a presentation to A*STAR and the Singapor...Python for Science and Engineering: a presentation to A*STAR and the Singapor...
Python for Science and Engineering: a presentation to A*STAR and the Singapor...pythoncharmers
 
开源沙龙第一期 Python intro
开源沙龙第一期 Python intro开源沙龙第一期 Python intro
开源沙龙第一期 Python introfantasy zheng
 
Learn Python Programming | Python Programming - Step by Step | Python for Beg...
Learn Python Programming | Python Programming - Step by Step | Python for Beg...Learn Python Programming | Python Programming - Step by Step | Python for Beg...
Learn Python Programming | Python Programming - Step by Step | Python for Beg...Edureka!
 
Seminar report on python 3 course
Seminar report on python 3 courseSeminar report on python 3 course
Seminar report on python 3 courseHimanshuPanwar38
 
Intro to Machine Learning Enpowered by Python (Montreal Python)
Intro to Machine Learning Enpowered by Python (Montreal Python)Intro to Machine Learning Enpowered by Python (Montreal Python)
Intro to Machine Learning Enpowered by Python (Montreal Python)Francis Piéraut
 
python for linguists
python for linguistspython for linguists
python for linguistsshukaihsieh
 
Python 101 for the .NET Developer
Python 101 for the .NET DeveloperPython 101 for the .NET Developer
Python 101 for the .NET DeveloperSarah Dutkiewicz
 
Benefits & features of python |Advantages & disadvantages of python
Benefits & features of python |Advantages & disadvantages of pythonBenefits & features of python |Advantages & disadvantages of python
Benefits & features of python |Advantages & disadvantages of pythonparadisetechsoftsolutions
 
First python project
First python projectFirst python project
First python projectNeetu Jain
 
Python: the Project, the Language and the Style
Python: the Project, the Language and the StylePython: the Project, the Language and the Style
Python: the Project, the Language and the StyleJuan-Manuel Gimeno
 
Python | What is Python | History of Python | Python Tutorial
Python | What is Python | History of Python | Python TutorialPython | What is Python | History of Python | Python Tutorial
Python | What is Python | History of Python | Python TutorialQA TrainingHub
 

What's hot (17)

pycon-2015-liza-daly
pycon-2015-liza-dalypycon-2015-liza-daly
pycon-2015-liza-daly
 
summer training report on python
summer training report on pythonsummer training report on python
summer training report on python
 
Introduction to Python
Introduction to PythonIntroduction to Python
Introduction to Python
 
Python Class 1
Python Class 1Python Class 1
Python Class 1
 
Chapter 8 getting started with python
Chapter 8 getting started with pythonChapter 8 getting started with python
Chapter 8 getting started with python
 
Machine Learning empowered by Python April2009
Machine Learning empowered by Python April2009Machine Learning empowered by Python April2009
Machine Learning empowered by Python April2009
 
Python for Science and Engineering: a presentation to A*STAR and the Singapor...
Python for Science and Engineering: a presentation to A*STAR and the Singapor...Python for Science and Engineering: a presentation to A*STAR and the Singapor...
Python for Science and Engineering: a presentation to A*STAR and the Singapor...
 
开源沙龙第一期 Python intro
开源沙龙第一期 Python intro开源沙龙第一期 Python intro
开源沙龙第一期 Python intro
 
Learn Python Programming | Python Programming - Step by Step | Python for Beg...
Learn Python Programming | Python Programming - Step by Step | Python for Beg...Learn Python Programming | Python Programming - Step by Step | Python for Beg...
Learn Python Programming | Python Programming - Step by Step | Python for Beg...
 
Seminar report on python 3 course
Seminar report on python 3 courseSeminar report on python 3 course
Seminar report on python 3 course
 
Intro to Machine Learning Enpowered by Python (Montreal Python)
Intro to Machine Learning Enpowered by Python (Montreal Python)Intro to Machine Learning Enpowered by Python (Montreal Python)
Intro to Machine Learning Enpowered by Python (Montreal Python)
 
python for linguists
python for linguistspython for linguists
python for linguists
 
Python 101 for the .NET Developer
Python 101 for the .NET DeveloperPython 101 for the .NET Developer
Python 101 for the .NET Developer
 
Benefits & features of python |Advantages & disadvantages of python
Benefits & features of python |Advantages & disadvantages of pythonBenefits & features of python |Advantages & disadvantages of python
Benefits & features of python |Advantages & disadvantages of python
 
First python project
First python projectFirst python project
First python project
 
Python: the Project, the Language and the Style
Python: the Project, the Language and the StylePython: the Project, the Language and the Style
Python: the Project, the Language and the Style
 
Python | What is Python | History of Python | Python Tutorial
Python | What is Python | History of Python | Python TutorialPython | What is Python | History of Python | Python Tutorial
Python | What is Python | History of Python | Python Tutorial
 

Viewers also liked

Python 3 Intro Presentation for NEWLUG
Python 3 Intro Presentation for NEWLUGPython 3 Intro Presentation for NEWLUG
Python 3 Intro Presentation for NEWLUGNEWLUG
 
Stackless Python 101
Stackless Python 101Stackless Python 101
Stackless Python 101guest162fd90
 
Python arsenal for re
Python arsenal for rePython arsenal for re
Python arsenal for regeeksec80
 
Python for pentesters
Python for pentestersPython for pentesters
Python for pentestersRashid feroz
 
DefCamp 2013 - MSF Into The Worm Hole
DefCamp 2013 - MSF Into The Worm HoleDefCamp 2013 - MSF Into The Worm Hole
DefCamp 2013 - MSF Into The Worm HoleDefCamp
 
Unix/Linux Basic Commands and Shell Script
Unix/Linux Basic Commands and Shell ScriptUnix/Linux Basic Commands and Shell Script
Unix/Linux Basic Commands and Shell Scriptsbmguys
 

Viewers also liked (7)

Python 3 Intro Presentation for NEWLUG
Python 3 Intro Presentation for NEWLUGPython 3 Intro Presentation for NEWLUG
Python 3 Intro Presentation for NEWLUG
 
Stackless Python 101
Stackless Python 101Stackless Python 101
Stackless Python 101
 
Python arsenal for re
Python arsenal for rePython arsenal for re
Python arsenal for re
 
Reverse engineering with python
Reverse engineering with pythonReverse engineering with python
Reverse engineering with python
 
Python for pentesters
Python for pentestersPython for pentesters
Python for pentesters
 
DefCamp 2013 - MSF Into The Worm Hole
DefCamp 2013 - MSF Into The Worm HoleDefCamp 2013 - MSF Into The Worm Hole
DefCamp 2013 - MSF Into The Worm Hole
 
Unix/Linux Basic Commands and Shell Script
Unix/Linux Basic Commands and Shell ScriptUnix/Linux Basic Commands and Shell Script
Unix/Linux Basic Commands and Shell Script
 

Similar to Scientific Programming in Python

Python in Scientific Computing.pdf
Python in Scientific Computing.pdfPython in Scientific Computing.pdf
Python in Scientific Computing.pdfAmirKhan811717
 
Python Scope In Future
Python Scope In FuturePython Scope In Future
Python Scope In FutureNaveenJindal20
 
Python Credit Activity.pptx
Python Credit Activity.pptxPython Credit Activity.pptx
Python Credit Activity.pptxvarun536341
 
Guide to Learn Python Programming.pdf
Guide to Learn Python Programming.pdfGuide to Learn Python Programming.pdf
Guide to Learn Python Programming.pdfNikhilSharma142682
 
Top Libraries for Machine Learning with Python
Top Libraries for Machine Learning with Python Top Libraries for Machine Learning with Python
Top Libraries for Machine Learning with Python Chariza Pladin
 
Programming for data science in python
Programming for data science in pythonProgramming for data science in python
Programming for data science in pythonUmmeSalmaM1
 
Python Projects For Beginners | Python Projects Examples | Python Tutorial | ...
Python Projects For Beginners | Python Projects Examples | Python Tutorial | ...Python Projects For Beginners | Python Projects Examples | Python Tutorial | ...
Python Projects For Beginners | Python Projects Examples | Python Tutorial | ...Edureka!
 
The-Power-of-Python-in-Computer-Science.pptx
The-Power-of-Python-in-Computer-Science.pptxThe-Power-of-Python-in-Computer-Science.pptx
The-Power-of-Python-in-Computer-Science.pptxAttitude Tally Academy
 
Python for Data Science: A Comprehensive Guide
Python for Data Science: A Comprehensive GuidePython for Data Science: A Comprehensive Guide
Python for Data Science: A Comprehensive GuideUncodemy
 
Python Programming Careers
Python Programming Careers Python Programming Careers
Python Programming Careers NaveenJindal20
 
PYTHON COURSE IN KHANNA
PYTHON COURSE IN KHANNAPYTHON COURSE IN KHANNA
PYTHON COURSE IN KHANNAtanukashyap18
 
Python Prodigy: Unraveling the Secrets of High-Level Programming
Python Prodigy: Unraveling the Secrets of High-Level ProgrammingPython Prodigy: Unraveling the Secrets of High-Level Programming
Python Prodigy: Unraveling the Secrets of High-Level ProgrammingUncodemy
 
Why to Choose Python for Data Science Master.pptx
Why to Choose Python for Data Science Master.pptxWhy to Choose Python for Data Science Master.pptx
Why to Choose Python for Data Science Master.pptxHGLLearn
 
QUICK START GUIDE FOR PYTHON
QUICK START GUIDE FOR PYTHON  QUICK START GUIDE FOR PYTHON
QUICK START GUIDE FOR PYTHON ActonRoy
 
Advantages of python for the internet of things
Advantages of python for the internet of thingsAdvantages of python for the internet of things
Advantages of python for the internet of thingsMaciej Dziergwa
 
python classes 1.pdf
python classes 1.pdfpython classes 1.pdf
python classes 1.pdfrobin singh
 

Similar to Scientific Programming in Python (20)

Python in Scientific Computing.pdf
Python in Scientific Computing.pdfPython in Scientific Computing.pdf
Python in Scientific Computing.pdf
 
what is python ?
what is python ? what is python ?
what is python ?
 
Python Scope In Future
Python Scope In FuturePython Scope In Future
Python Scope In Future
 
Python Mastery Made Easy.pdf
Python Mastery Made Easy.pdfPython Mastery Made Easy.pdf
Python Mastery Made Easy.pdf
 
Python Credit Activity.pptx
Python Credit Activity.pptxPython Credit Activity.pptx
Python Credit Activity.pptx
 
Guide to Learn Python Programming.pdf
Guide to Learn Python Programming.pdfGuide to Learn Python Programming.pdf
Guide to Learn Python Programming.pdf
 
Top Libraries for Machine Learning with Python
Top Libraries for Machine Learning with Python Top Libraries for Machine Learning with Python
Top Libraries for Machine Learning with Python
 
Programming for data science in python
Programming for data science in pythonProgramming for data science in python
Programming for data science in python
 
Python Projects For Beginners | Python Projects Examples | Python Tutorial | ...
Python Projects For Beginners | Python Projects Examples | Python Tutorial | ...Python Projects For Beginners | Python Projects Examples | Python Tutorial | ...
Python Projects For Beginners | Python Projects Examples | Python Tutorial | ...
 
The-Power-of-Python-in-Computer-Science.pptx
The-Power-of-Python-in-Computer-Science.pptxThe-Power-of-Python-in-Computer-Science.pptx
The-Power-of-Python-in-Computer-Science.pptx
 
Python for Data Science: A Comprehensive Guide
Python for Data Science: A Comprehensive GuidePython for Data Science: A Comprehensive Guide
Python for Data Science: A Comprehensive Guide
 
Python Programming Careers
Python Programming Careers Python Programming Careers
Python Programming Careers
 
PYTHON COURSE IN KHANNA
PYTHON COURSE IN KHANNAPYTHON COURSE IN KHANNA
PYTHON COURSE IN KHANNA
 
Python Prodigy: Unraveling the Secrets of High-Level Programming
Python Prodigy: Unraveling the Secrets of High-Level ProgrammingPython Prodigy: Unraveling the Secrets of High-Level Programming
Python Prodigy: Unraveling the Secrets of High-Level Programming
 
Why to Choose Python for Data Science Master.pptx
Why to Choose Python for Data Science Master.pptxWhy to Choose Python for Data Science Master.pptx
Why to Choose Python for Data Science Master.pptx
 
Best Python Institute in Noida. pptx
Best Python Institute in Noida.      pptxBest Python Institute in Noida.      pptx
Best Python Institute in Noida. pptx
 
QUICK START GUIDE FOR PYTHON
QUICK START GUIDE FOR PYTHON  QUICK START GUIDE FOR PYTHON
QUICK START GUIDE FOR PYTHON
 
industrial training.pptx
industrial training.pptxindustrial training.pptx
industrial training.pptx
 
Advantages of python for the internet of things
Advantages of python for the internet of thingsAdvantages of python for the internet of things
Advantages of python for the internet of things
 
python classes 1.pdf
python classes 1.pdfpython classes 1.pdf
python classes 1.pdf
 

More from zukun

My lyn tutorial 2009
My lyn tutorial 2009My lyn tutorial 2009
My lyn tutorial 2009zukun
 
ETHZ CV2012: Tutorial openCV
ETHZ CV2012: Tutorial openCVETHZ CV2012: Tutorial openCV
ETHZ CV2012: Tutorial openCVzukun
 
ETHZ CV2012: Information
ETHZ CV2012: InformationETHZ CV2012: Information
ETHZ CV2012: Informationzukun
 
Siwei lyu: natural image statistics
Siwei lyu: natural image statisticsSiwei lyu: natural image statistics
Siwei lyu: natural image statisticszukun
 
Lecture9 camera calibration
Lecture9 camera calibrationLecture9 camera calibration
Lecture9 camera calibrationzukun
 
Brunelli 2008: template matching techniques in computer vision
Brunelli 2008: template matching techniques in computer visionBrunelli 2008: template matching techniques in computer vision
Brunelli 2008: template matching techniques in computer visionzukun
 
Modern features-part-4-evaluation
Modern features-part-4-evaluationModern features-part-4-evaluation
Modern features-part-4-evaluationzukun
 
Modern features-part-3-software
Modern features-part-3-softwareModern features-part-3-software
Modern features-part-3-softwarezukun
 
Modern features-part-2-descriptors
Modern features-part-2-descriptorsModern features-part-2-descriptors
Modern features-part-2-descriptorszukun
 
Modern features-part-1-detectors
Modern features-part-1-detectorsModern features-part-1-detectors
Modern features-part-1-detectorszukun
 
Modern features-part-0-intro
Modern features-part-0-introModern features-part-0-intro
Modern features-part-0-introzukun
 
Lecture 02 internet video search
Lecture 02 internet video searchLecture 02 internet video search
Lecture 02 internet video searchzukun
 
Lecture 01 internet video search
Lecture 01 internet video searchLecture 01 internet video search
Lecture 01 internet video searchzukun
 
Lecture 03 internet video search
Lecture 03 internet video searchLecture 03 internet video search
Lecture 03 internet video searchzukun
 
Icml2012 tutorial representation_learning
Icml2012 tutorial representation_learningIcml2012 tutorial representation_learning
Icml2012 tutorial representation_learningzukun
 
Advances in discrete energy minimisation for computer vision
Advances in discrete energy minimisation for computer visionAdvances in discrete energy minimisation for computer vision
Advances in discrete energy minimisation for computer visionzukun
 
Gephi tutorial: quick start
Gephi tutorial: quick startGephi tutorial: quick start
Gephi tutorial: quick startzukun
 
EM algorithm and its application in probabilistic latent semantic analysis
EM algorithm and its application in probabilistic latent semantic analysisEM algorithm and its application in probabilistic latent semantic analysis
EM algorithm and its application in probabilistic latent semantic analysiszukun
 
Object recognition with pictorial structures
Object recognition with pictorial structuresObject recognition with pictorial structures
Object recognition with pictorial structureszukun
 
Iccv2011 learning spatiotemporal graphs of human activities
Iccv2011 learning spatiotemporal graphs of human activities Iccv2011 learning spatiotemporal graphs of human activities
Iccv2011 learning spatiotemporal graphs of human activities zukun
 

More from zukun (20)

My lyn tutorial 2009
My lyn tutorial 2009My lyn tutorial 2009
My lyn tutorial 2009
 
ETHZ CV2012: Tutorial openCV
ETHZ CV2012: Tutorial openCVETHZ CV2012: Tutorial openCV
ETHZ CV2012: Tutorial openCV
 
ETHZ CV2012: Information
ETHZ CV2012: InformationETHZ CV2012: Information
ETHZ CV2012: Information
 
Siwei lyu: natural image statistics
Siwei lyu: natural image statisticsSiwei lyu: natural image statistics
Siwei lyu: natural image statistics
 
Lecture9 camera calibration
Lecture9 camera calibrationLecture9 camera calibration
Lecture9 camera calibration
 
Brunelli 2008: template matching techniques in computer vision
Brunelli 2008: template matching techniques in computer visionBrunelli 2008: template matching techniques in computer vision
Brunelli 2008: template matching techniques in computer vision
 
Modern features-part-4-evaluation
Modern features-part-4-evaluationModern features-part-4-evaluation
Modern features-part-4-evaluation
 
Modern features-part-3-software
Modern features-part-3-softwareModern features-part-3-software
Modern features-part-3-software
 
Modern features-part-2-descriptors
Modern features-part-2-descriptorsModern features-part-2-descriptors
Modern features-part-2-descriptors
 
Modern features-part-1-detectors
Modern features-part-1-detectorsModern features-part-1-detectors
Modern features-part-1-detectors
 
Modern features-part-0-intro
Modern features-part-0-introModern features-part-0-intro
Modern features-part-0-intro
 
Lecture 02 internet video search
Lecture 02 internet video searchLecture 02 internet video search
Lecture 02 internet video search
 
Lecture 01 internet video search
Lecture 01 internet video searchLecture 01 internet video search
Lecture 01 internet video search
 
Lecture 03 internet video search
Lecture 03 internet video searchLecture 03 internet video search
Lecture 03 internet video search
 
Icml2012 tutorial representation_learning
Icml2012 tutorial representation_learningIcml2012 tutorial representation_learning
Icml2012 tutorial representation_learning
 
Advances in discrete energy minimisation for computer vision
Advances in discrete energy minimisation for computer visionAdvances in discrete energy minimisation for computer vision
Advances in discrete energy minimisation for computer vision
 
Gephi tutorial: quick start
Gephi tutorial: quick startGephi tutorial: quick start
Gephi tutorial: quick start
 
EM algorithm and its application in probabilistic latent semantic analysis
EM algorithm and its application in probabilistic latent semantic analysisEM algorithm and its application in probabilistic latent semantic analysis
EM algorithm and its application in probabilistic latent semantic analysis
 
Object recognition with pictorial structures
Object recognition with pictorial structuresObject recognition with pictorial structures
Object recognition with pictorial structures
 
Iccv2011 learning spatiotemporal graphs of human activities
Iccv2011 learning spatiotemporal graphs of human activities Iccv2011 learning spatiotemporal graphs of human activities
Iccv2011 learning spatiotemporal graphs of human activities
 

Recently uploaded

CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...anjaliyadav012327
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
The byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxThe byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxShobhayan Kirtania
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 

Recently uploaded (20)

CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
The byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxThe byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptx
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 

Scientific Programming in Python

  • 1. Why Python? Introduction to Python Further Info Scientific Programming in Python Eric Christiansen UCSD CSE September 16, 2008 This work is licensed under the Creative Commons Attribution 3.0 License. Based on a MATLAB tutorial by Tim Marks Scientific Programming in Python 1 / 22
  • 2. Why Python? Introduction to Python Further Info What is Python? Python in a very high level (scripting) language which has gained widespread popularity in recent years. It is: Scientific Programming in Python 2 / 22
  • 3. Why Python? Introduction to Python Further Info What is Python? Python in a very high level (scripting) language which has gained widespread popularity in recent years. It is: cross platform Scientific Programming in Python 2 / 22
  • 4. Why Python? Introduction to Python Further Info What is Python? Python in a very high level (scripting) language which has gained widespread popularity in recent years. It is: cross platform object oriented Scientific Programming in Python 2 / 22
  • 5. Why Python? Introduction to Python Further Info What is Python? Python in a very high level (scripting) language which has gained widespread popularity in recent years. It is: cross platform object oriented open source Scientific Programming in Python 2 / 22
  • 6. Why Python? Introduction to Python Further Info Why should I care? Scientific Programming in Python 3 / 22
  • 7. Why Python? Introduction to Python Further Info Why should I care? You may need to use a computer to run simulations crunch data display data... Scientific Programming in Python 3 / 22
  • 8. Why Python? Introduction to Python Further Info Why should I care? You may need to use a computer to run simulations crunch data display data... Python’s 3rd -party libraries can help you with these tasks. Scientific Programming in Python 3 / 22
  • 9. Why Python? Introduction to Python Further Info Python’s Scientific Libraries Python is enhanced by a large set of scientific libraries that are being actively developed. Scientific Programming in Python 4 / 22
  • 10. Why Python? Introduction to Python Further Info Python’s Scientific Libraries Python is enhanced by a large set of scientific libraries that are being actively developed. standard science and engineering functions or plotting (MATLAB) SciPy, Matplotlib Scientific Programming in Python 4 / 22
  • 11. Why Python? Introduction to Python Further Info Python’s Scientific Libraries Python is enhanced by a large set of scientific libraries that are being actively developed. standard science and engineering functions or plotting (MATLAB) SciPy, Matplotlib a computer algebra system (Mathematica) SAGE Scientific Programming in Python 4 / 22
  • 12. Why Python? Introduction to Python Further Info Python’s Scientific Libraries Scientific Programming in Python 5 / 22
  • 13. Why Python? Introduction to Python Further Info Python’s Scientific Libraries data processing Modular toolkit for Data Processing (MDP) Scientific Programming in Python 5 / 22
  • 14. Why Python? Introduction to Python Further Info Python’s Scientific Libraries data processing Modular toolkit for Data Processing (MDP) bioinformatics functions Biopython Scientific Programming in Python 5 / 22
  • 15. Why Python? Introduction to Python Further Info Python’s Scientific Libraries data processing Modular toolkit for Data Processing (MDP) bioinformatics functions Biopython machine learning functions PyML, mlpy, SHOGUN Scientific Programming in Python 5 / 22
  • 16. Why Python? Introduction to Python Further Info Python’s Scientific Libraries data processing Modular toolkit for Data Processing (MDP) bioinformatics functions Biopython machine learning functions PyML, mlpy, SHOGUN neural nets Fast Artificial Neural Network (FANN) Library Scientific Programming in Python 5 / 22
  • 17. Why Python? Introduction to Python Further Info Python’s Scientific Libraries data processing Modular toolkit for Data Processing (MDP) bioinformatics functions Biopython machine learning functions PyML, mlpy, SHOGUN neural nets Fast Artificial Neural Network (FANN) Library artificial intelligence or robotics routines Python Robotics (Pyro) Scientific Programming in Python 5 / 22
  • 18. Why Python? Introduction to Python Further Info Is it hard to learn? Scientific Programming in Python 6 / 22
  • 19. Why Python? Introduction to Python Further Info Is it hard to learn? Scientific Programming in Python 6 / 22
  • 20. Why Python? Introduction to Python Further Info Python vs MATLAB Advantages of MATLAB: Scientific Programming in Python 7 / 22
  • 21. Why Python? Introduction to Python Further Info Python vs MATLAB Advantages of MATLAB: already widely used Scientific Programming in Python 7 / 22
  • 22. Why Python? Introduction to Python Further Info Python vs MATLAB Advantages of MATLAB: already widely used designed specifically for scientific computing Scientific Programming in Python 7 / 22
  • 23. Why Python? Introduction to Python Further Info Python vs MATLAB Advantages of MATLAB: already widely used designed specifically for scientific computing easy to find documentation Scientific Programming in Python 7 / 22
  • 24. Why Python? Introduction to Python Further Info Python vs MATLAB Advantages of MATLAB: already widely used designed specifically for scientific computing easy to find documentation good IDE with debugging and profiling support “out of the box” Scientific Programming in Python 7 / 22
  • 25. Why Python? Introduction to Python Further Info Python vs MATLAB Advantages of MATLAB: already widely used designed specifically for scientific computing easy to find documentation good IDE with debugging and profiling support “out of the box” Advantages of Python: Scientific Programming in Python 7 / 22
  • 26. Why Python? Introduction to Python Further Info Python vs MATLAB Advantages of MATLAB: already widely used designed specifically for scientific computing easy to find documentation good IDE with debugging and profiling support “out of the box” Advantages of Python: open source means no limits on use Scientific Programming in Python 7 / 22
  • 27. Why Python? Introduction to Python Further Info Python vs MATLAB Advantages of MATLAB: already widely used designed specifically for scientific computing easy to find documentation good IDE with debugging and profiling support “out of the box” Advantages of Python: open source means no limits on use appears to approximately superset MATLAB’s functionality Scientific Programming in Python 7 / 22
  • 28. Why Python? Introduction to Python Further Info Python vs MATLAB Advantages of MATLAB: already widely used designed specifically for scientific computing easy to find documentation good IDE with debugging and profiling support “out of the box” Advantages of Python: open source means no limits on use appears to approximately superset MATLAB’s functionality modern language with support for object orientation Scientific Programming in Python 7 / 22
  • 29. Why Python? Introduction to Python Further Info Python vs MATLAB Advantages of MATLAB: already widely used designed specifically for scientific computing easy to find documentation good IDE with debugging and profiling support “out of the box” Advantages of Python: open source means no limits on use appears to approximately superset MATLAB’s functionality modern language with support for object orientation support for calling functions in other languages Scientific Programming in Python 7 / 22
  • 30. Why Python? Introduction to Python Further Info Basics To get information on an object from the interpreter h e l p <o b j e c t > Commenting: Inline comments are preceded with # Block comments are surrounded with ””” Code blocks are denoted with indentation: i f x == 2 : print x Python is dynamically typed: a = ”hello” # a is a string a = 4 # a i s now an i n t e g e r Scientific Programming in Python 8 / 22
  • 31. Why Python? Introduction to Python Further Info Vectors Many of these functions come from SciPy. from s c i p y import ∗ Vectors: N = 5 # a scalar v = [1 ,2 ,3] # a list v = array ([1 ,2 ,3]) # a column v e c t o r v = a r r a y ( [ [ 1 ] , [ 2 ] , [ 3 ] ] )# a column v e c t o r v = array ([[1 ,2 ,3]]) # a column v e c t o r v = transpose (v) # transpose a vector # ( row t o column # o r column t o row ) v = a r a n g e ( −4 ,4) # a vector in # a s p e c i f i e d range : v = p i ∗ a r a n g e ( −4 ,4)/4 v = arange ( −4 ,4 ,.5) # arange ( s t a r t , stop , s t e p ) v = [] # empty l i s t Scientific Programming in Python 9 / 22
  • 32. Why Python? Introduction to Python Further Info Matrices v = array ([5 ,6 ,7]) # access a vector element v [2] # vector ( index ) − arrays are # z e r o −i n d e x e d len (v) # number o f e l e m e n t s i n a v e c t o r m = array ([[1 ,2 ,3] , [4 ,5 ,6]]) # a 2 x3 m a t r i x m[ 1 , 2 ] == m [ 1 ] [ 2 ] # access a matrix element # m a t r i x [ row , column ] Scientific Programming in Python 10 / 22
  • 33. Why Python? Introduction to Python Further Info Syntax and Special Functions Matrices: m = zeros ([2 ,3]) # a matrix of zeros v = ones ( [ 1 , 3 ] ) # a matrix of ones v = rand (3 ,1) # rand matrix ( see a l s o randn ) m = eye (3) # i d e n t i t y m a t r i x ( 3 x3 ) Scientific Programming in Python 11 / 22
  • 34. Why Python? Introduction to Python Further Info Syntax and Special Functions (cont) m[ 1 , : ] # a c c e s s a m a t r i x row ( s e c o n d row ) m[ : , 0 ] # a c c e s s a m a t r i x column ( l e f t column ) m[ 1 : , 1 : ] # lower r i g h t submatrix m. r e s h a p e ( [ 4 , 1 ] ) # t u r n m a t r i x i n t o a column # v e c t o r ( c o n c a t e n a t e rows ) m. s h a p e # s i z e o f a m a t r i x [ rows , c o l s ] m. s h a p e [ 0 ] # number o f rows m. s h a p e [ 1 ] # number o f c o l u m n s z e r o s (m. s h a p e ) # c r e a t e a new m a t r i x w i t h # s i z e of m m = a r r a y ( [ [ ’ h e l l o ’ , sum ] , [1 ,2]]) # p u t w h a t e v e r you want # i n t o an a r r a y m[ 0 , 1 ] (m[ 1 ] ) # c a l l sum on bottom row o f m Scientific Programming in Python 12 / 22
  • 35. Why Python? Introduction to Python Further Info Syntax and Special Functions (cont) Arithmetic operations performed on arrays are done “element by element”. a = array ([1 ,2 ,3 ,4]) # vector 2 ∗ a # scalar multiplication a / 4 # scalar division b = array ([5 ,6 ,7 ,8]) # vector a + b # pointwise vector addition a − b # pointwise vector subtraction a ∗∗ 2 # pointise vector squaring a ∗ b # pointwise vector multiply a / b # pointwise vector divide log (a) # pointwise logarithm around ( a r r a y ( [ [ . 6 ] , [.5]])) # pointwise rounding # ( . 5 rounds to 0) Scientific Programming in Python 13 / 22
  • 36. Why Python? Introduction to Python Further Info Vector Operations a = array ([1 ,4 ,6 ,3]) # vector sum ( a ) # sum o f v e c t o r e l e m e n t s mean ( a ) # mean o f v e c t o r e l e m e n t s var (a) # variance std (a) # standard deviation max ( a ) # maximum a = array ([[1 ,2 ,3] , [4 ,5 ,6]]) # matrix mean ( a , 0 ) # mean o f e a c h column amax ( a , 1 ) # max o f e a c h row amax ( a ) # t o o b t a i n max o f m a t r i x # n o t e we u s e 2 # d i f f e r e n t max f u n c t i o n s Scientific Programming in Python 14 / 22
  • 37. Why Python? Introduction to Python Further Info Matrix Operations dot ( t r a n s p o s e ( a r r a y ( [ 1 , 2 , 3 ] ) ) , array ([4 ,5 ,6])) # row v e c t o r 1 x3 t i m e s column # v e c t o r 3 x1 r e s u l t s i n a # s i n g l e number , a l s o known # as dot / i n n e r product dot ( a r r a y ( [ [ 1 ] , [ 2 ] , [ 3 ] ] ) , a r r a y ( [ [ 4 , 5 , 6 ] ] ) ) # column v e c t o r 3 x1 t i m e s row # v e c t o r 1 x3 r e s u l t s i n 3 x3 # m a t r i x , a l s o known # as outer product a = rand (3 ,2) # 3 x2 m a t r i x b = rand (2 ,4) # 2 x4 m a t r i x dot ( a , b ) # 3 x4 m a t r i x Scientific Programming in Python 15 / 22
  • 38. Why Python? Introduction to Python Further Info Saving Your Work import c P i c k l e a s p i c k l e # t h i s module l e t s you # s a v e and r e l o a d o b j e c t s f = open ( ’ s a v e f i l e ’ , ’w ’ ) # open a r c h i v e f i l e p i c k l e . dump ( o b j , f ) # dump o b j e c t t o a r c h i v e f . close () # close archive f i l e del obj # clear object # from memory f = open ( ’ s a v e f i l e ’ , ’ r ’ ) # open archive f i l e obj = p i c k l e . load ( f ) # read object # from archive f . close () # close archive f i l e Scientific Programming in Python 16 / 22
  • 39. Why Python? Introduction to Python Further Info Relations and Control Example: given a list v, create a new list u with values equal to v if they are greater than 0, and equal to 0 if they less than or equal to 0. Using a for loop: v = [3 ,5 , −2 ,5 , −1 ,0] u = [0] ∗ len (v) # u is a l l zeros for i in range ( len ( v ) ) : i f v [ i ] > 0: u[ i ] = v[ i ] Using list comprehension: v = [3 ,5 , −2 ,5 , −1 ,0] u = [ max ( e , 0 ) f o r e i n v ] Scientific Programming in Python 17 / 22
  • 40. Why Python? Introduction to Python Further Info Importing Functions Save the following code to “mylib.py”: def myfunc ( a , b ) : r e t u r n a+b ∗∗2 Import and use myfunc. Note, we might need to configure PYTHONPATH. from m y l i b import myfunc myfunc ( 1 , 2 ) myfunc ( b=2, a=1) # same a s a bo v e Python also supports class creation: c l a s s MyClass : def init ( self ): print ” hello ! ” m y c l a s s = MyClass ( ) Scientific Programming in Python 18 / 22
  • 41. Why Python? Introduction to Python Further Info Plotting The library matplotlib / pylab is your friend: from p y l a b import ∗ xs = arange ( −2 ,2 ,.01) p l o t ( xs , s i n ( x s ) ) show ( ) Scientific Programming in Python 19 / 22
  • 42. Why Python? Introduction to Python Further Info Imaging We use the Python Imaging Library as well as matplotlib / pylab. from p y l a b import ∗ import Image im = Image . open ( ’ my image . j p g ’ ) im . show ( ) # we can d i s p l a y t h e image ima = a r r a y ( im ) # t y p e c a s t i n g to a r r a y # extracts pixel values i m r = Image . f r o m s t r i n g ( ’RGB ’ , ( ima . s h a p e [ 1 ] , ima . s h a p e [ 0 ] ) , ima . t o s t r i n g ( ) ) # c o n v e r t a r r a y i n t o image img = mean ( ima , 2 ) # average color i n t e n s i t i e s # f o r each p i x e l imshow ( img ) autumn ( ) # s e t d e f a u l t c o l o r m a p t o autumn show ( ) Scientific Programming in Python 20 / 22
  • 43. Why Python? Introduction to Python Further Info More Help? Many guides and tutorials are available online: Scientific Programming in Python 21 / 22
  • 44. Why Python? Introduction to Python Further Info More Help? Many guides and tutorials are available online: Dive Into Python python introduction for programmers Scientific Programming in Python 21 / 22
  • 45. Why Python? Introduction to Python Further Info More Help? Many guides and tutorials are available online: Dive Into Python python introduction for programmers A list of tutorials for Python and some of its many libraries can be found at http://www.awaretek.com/tutorials.html Scientific Programming in Python 21 / 22
  • 46. Why Python? Introduction to Python Further Info Questions? Scientific Programming in Python 22 / 22