SlideShare une entreprise Scribd logo
1  sur  19
Télécharger pour lire hors ligne
Introduction to Python
and Scientific Python
Fran¸cois Bianco
Unige
21th Dec 2011
Fran¸cois Bianco Introduction to Python
Outlook
1 Python features and syntax
2 Examples, pylab, and iPython
3 Flat files examples
Based on :
Learn Python in 10 minutes :
http://www.poromenos.org/tutorials/python
Python documentation : http://docs.python.org/index.html
Matplotlib : http://matplotlib.sourceforge.net/
Scipy : http://www.scipy.org/
Fran¸cois Bianco Introduction to Python
Python is
Strongly typed (i.e. types are enforced)
Dynamically, implicitly typed (i.e. you don’t have to declare
variables)
Python is
case sensitive (i.e. var and VAR are two different variables)
object-oriented (i.e. everything is an object)
able to handle memory by itself (i.e has a garbadge collector)
Fran¸cois Bianco Introduction to Python
Example
Example
l i s t = [1 ,1.1 ,1+1 j , ’ 1 ’ , True ]
for element in l i s t :
print element , type ( element ) , element==1.1
No mandatory statement termination character
Blocks are specified by indentation (4 spaces, or 1 tab)
Statements that expect an indentation level end in a colon “:”
Values are assigned (in fact, objects are bound to names) with
the equals sign “=”
Equality testing is done using two equals signs “==”
Fran¸cois Bianco Introduction to Python
Data structures
Three main data structures
list = [1,2,3,4,5,6] are mutable
tuples = (1,2,3,4,5,6) are unmutable
dictionary = { ’key’:’value’, ’answer’:42, ’obj’:list } also called
hash tables, access by key
List and tuples are access by index : list[index] (see array slicing).
Dictionary by key dictionary[’answer’].
Fran¸cois Bianco Introduction to Python
Modules loading
Classes and functions are stored in modules
from math import s i n #only one f u n c t i o n
s i n ( 0 . 3 )
import math #the whole module keeping namespace
math . s i n ( 0 . 3 )
from math import * #the whole module
cos ( 0 . 3 )
import m a t p l o t l i b as mptl #rename namespace
mptl . c o n v e r t e r ()
Fran¸cois Bianco Introduction to Python
Other features of Python
Modern way of handling errors
try :
f i l e O b j = open ( ’ fileName . t x t ’ )
except IOError :
print ErrorMessage
Lambda functions
f i t f u n c = lambda x , y : s q r t ( x/y )
f i t f u n c ( 4 . 5 , 2 . 3 )
Fran¸cois Bianco Introduction to Python
Other features of Python
Classes, functions...
def functionName ( param , optionalParam=value ) : . . .
class C h i l d C l a s s ( ParentClass ) : . . .
Automatic documentation generation (with Doxygen)
def toggleImages ( s e l f , event ) :
””” Toggle the two images according
to the t r i g g e r event .
param event Key or mouse event
t r i g g e r i n g the f u n c t i o n
”””
Fran¸cois Bianco Introduction to Python
Flow control statements
Example: Fibonnaci in a simple while loop
a , b = 0 ,1
while b<10:
print b
a , b = b , a+b
Easy variables assignation, and permutation, no extra variable
needed.
Fran¸cois Bianco Introduction to Python
Array slicing
Example: access to specific elements in an array
x = arange (10) #c r e a t e a vector from 0 to 9
x #the whole vector
x [ 0 ] #only the f i r s t element
x [ 3 ] #the 3 rd element
x [ −2] #the second l a t e s t element
x [ 1 : 4 ] #elements from 1 to 4
x [ : 5 ] #elements up to 5
x [ −3:] #the three l a s t elements
Fran¸cois Bianco Introduction to Python
Array masking
Example: create a mask on an array
a = arange (10)
mask = (( a % 2) == 0)
a [ mask ] = 0
This sets all the even value in a to 0.
Fran¸cois Bianco Introduction to Python
Easy plot
Example : plot with label and LATEX title
p l o t ( arange (5))
x l a b e l ( ’ Index ’ )
y l a b e l ( ’Sum ’ )
t i t l e ( r ’ $sum { i =0}ˆ i n f t y i $ ’ )
Fran¸cois Bianco Introduction to Python
Display matrix as an image
Example : create an image from a matrix
x = randn (20 ,20) #c r e a t e a random 20 x20 matrix
imshow ( x ) #p i x e l s c a l e
imshow ( x , extent =(0 ,1 ,0 ,1)) #add custom s c a l e
Fran¸cois Bianco Introduction to Python
Histogramm plot
Example : create an histogramm plot
mu, sigma = 100 , 15
x = mu + sigma * randn (10000)
h i s t ( x ,100)
Fran¸cois Bianco Introduction to Python
Many plots
Example : create two plots with legend
t = arange (0 ,5 ,0.05) # Vect . 0 , 0 . 0 5 , 0 . 1 , . . . , 5
s1=s i n (2* pi * t )
s2=s1 *exp(−t )
p l o t ( t , s1 , ’g−−o ’ , t , s2 , ’ r : s ’ ) # custom s t y l e s
legend (( ’ Sin wave ’ , ’Damped exp . ’ ))
Fran¸cois Bianco Introduction to Python
iPython
Usefull magic commands in iPython
help ( obj ) #Show help
obj ? #Show doc s t r i n g
obj ?? #Show source code
#r e t u r n l a s t value
%who #l i s t o b j e c t s
%whos #d e t a i l l e d o b j e c t s l i s t
%h i s t −n #h i s t o r y without l i n e number
%exec In [ 4 : 7 ] #redo l i n e 4 to 7
%e d i t 4:7 #e d i t l i n e 4 to 7 in s c r i p t
%run #launch a s c r i p t
% p f i l e #show source f i l e content
You want more of it ? Try %lsmagic
Fran¸cois Bianco Introduction to Python
Pro and cons
Cons
No GUI
Documentation spread on different websites
Requires basics programming skills
Pro
Easy to learn
Work on every plateform (WinXP,Vista,MacOS,Linux,...)
Could be bind to Gwyddion
It’s a free software
Fran¸cois Bianco Introduction to Python
Other good reasons to learn Python
Used by different universities and research centers : University
of Montreal, Princeton University, Space Telescope Science
Institute, Los Alamos National Laboratory, UC Berkeley, CERN,
NASA ...
If you want to look for a job in some “small” companies :
Google, HP, IBM, Nokia, Thawte Consulting (SSL certificates), EA
Games, Industrial Light & Magic (Hollywood), ...
Fran¸cois Bianco Introduction to Python
The end
“There should be one – and preferably only one –
obvious way to do it.”
Tim Peters, The Zen of Python
Fran¸cois Bianco Introduction to Python

Contenu connexe

Tendances

A "Do-It-Yourself" Specification Language with BeepBeep 3 (Talk @ Dagstuhl 2017)
A "Do-It-Yourself" Specification Language with BeepBeep 3 (Talk @ Dagstuhl 2017)A "Do-It-Yourself" Specification Language with BeepBeep 3 (Talk @ Dagstuhl 2017)
A "Do-It-Yourself" Specification Language with BeepBeep 3 (Talk @ Dagstuhl 2017)Sylvain Hallé
 
Activity Recognition Through Complex Event Processing: First Findings
Activity Recognition Through Complex Event Processing: First Findings Activity Recognition Through Complex Event Processing: First Findings
Activity Recognition Through Complex Event Processing: First Findings Sylvain Hallé
 
Use the Matplotlib, Luke @ PyCon Taiwan 2012
Use the Matplotlib, Luke @ PyCon Taiwan 2012Use the Matplotlib, Luke @ PyCon Taiwan 2012
Use the Matplotlib, Luke @ PyCon Taiwan 2012Wen-Wei Liao
 
Function recap
Function recapFunction recap
Function recapalish sha
 
01 stack 20160908_jintaek_seo
01 stack 20160908_jintaek_seo01 stack 20160908_jintaek_seo
01 stack 20160908_jintaek_seoJinTaek Seo
 
Python for Scientific Computing -- Ricardo Cruz
Python for Scientific Computing -- Ricardo CruzPython for Scientific Computing -- Ricardo Cruz
Python for Scientific Computing -- Ricardo Cruzrpmcruz
 
Hacker Thursdays: An introduction to binary exploitation
Hacker Thursdays: An introduction to binary exploitationHacker Thursdays: An introduction to binary exploitation
Hacker Thursdays: An introduction to binary exploitationOWASP Hacker Thursday
 
[C++ Korea] Effective Modern C++ Study, Item 11 - 13
[C++ Korea] Effective Modern C++ Study, Item 11 - 13[C++ Korea] Effective Modern C++ Study, Item 11 - 13
[C++ Korea] Effective Modern C++ Study, Item 11 - 13Chris Ohk
 
When RV Meets CEP (RV 2016 Tutorial)
When RV Meets CEP (RV 2016 Tutorial)When RV Meets CEP (RV 2016 Tutorial)
When RV Meets CEP (RV 2016 Tutorial)Sylvain Hallé
 
Introduction to cython: example of GCoptimization
Introduction to cython: example of GCoptimizationIntroduction to cython: example of GCoptimization
Introduction to cython: example of GCoptimizationKevin Keraudren
 
Computer Architecture and Organization lab with matlab
Computer Architecture and Organization lab with matlabComputer Architecture and Organization lab with matlab
Computer Architecture and Organization lab with matlabShankar Gangaju
 
Presention programming
Presention programmingPresention programming
Presention programmingsaleha iqbal
 
CS50 Lecture4
CS50 Lecture4CS50 Lecture4
CS50 Lecture4昀 李
 
D vs OWKN Language at LLnagoya
D vs OWKN Language at LLnagoyaD vs OWKN Language at LLnagoya
D vs OWKN Language at LLnagoyaN Masahiro
 
Rust - Fernando Borretti
Rust - Fernando BorrettiRust - Fernando Borretti
Rust - Fernando BorrettiTryolabs
 
Format string vunerability
Format string vunerabilityFormat string vunerability
Format string vunerabilitynuc13us
 

Tendances (20)

A "Do-It-Yourself" Specification Language with BeepBeep 3 (Talk @ Dagstuhl 2017)
A "Do-It-Yourself" Specification Language with BeepBeep 3 (Talk @ Dagstuhl 2017)A "Do-It-Yourself" Specification Language with BeepBeep 3 (Talk @ Dagstuhl 2017)
A "Do-It-Yourself" Specification Language with BeepBeep 3 (Talk @ Dagstuhl 2017)
 
Activity Recognition Through Complex Event Processing: First Findings
Activity Recognition Through Complex Event Processing: First Findings Activity Recognition Through Complex Event Processing: First Findings
Activity Recognition Through Complex Event Processing: First Findings
 
Use the Matplotlib, Luke @ PyCon Taiwan 2012
Use the Matplotlib, Luke @ PyCon Taiwan 2012Use the Matplotlib, Luke @ PyCon Taiwan 2012
Use the Matplotlib, Luke @ PyCon Taiwan 2012
 
Function recap
Function recapFunction recap
Function recap
 
01 stack 20160908_jintaek_seo
01 stack 20160908_jintaek_seo01 stack 20160908_jintaek_seo
01 stack 20160908_jintaek_seo
 
Tiramisu概要
Tiramisu概要Tiramisu概要
Tiramisu概要
 
Python for Scientific Computing -- Ricardo Cruz
Python for Scientific Computing -- Ricardo CruzPython for Scientific Computing -- Ricardo Cruz
Python for Scientific Computing -- Ricardo Cruz
 
Hacker Thursdays: An introduction to binary exploitation
Hacker Thursdays: An introduction to binary exploitationHacker Thursdays: An introduction to binary exploitation
Hacker Thursdays: An introduction to binary exploitation
 
[C++ Korea] Effective Modern C++ Study, Item 11 - 13
[C++ Korea] Effective Modern C++ Study, Item 11 - 13[C++ Korea] Effective Modern C++ Study, Item 11 - 13
[C++ Korea] Effective Modern C++ Study, Item 11 - 13
 
When RV Meets CEP (RV 2016 Tutorial)
When RV Meets CEP (RV 2016 Tutorial)When RV Meets CEP (RV 2016 Tutorial)
When RV Meets CEP (RV 2016 Tutorial)
 
Pointer
PointerPointer
Pointer
 
Matplotlib
MatplotlibMatplotlib
Matplotlib
 
Introduction to cython: example of GCoptimization
Introduction to cython: example of GCoptimizationIntroduction to cython: example of GCoptimization
Introduction to cython: example of GCoptimization
 
Computer Architecture and Organization lab with matlab
Computer Architecture and Organization lab with matlabComputer Architecture and Organization lab with matlab
Computer Architecture and Organization lab with matlab
 
Presention programming
Presention programmingPresention programming
Presention programming
 
CS50 Lecture4
CS50 Lecture4CS50 Lecture4
CS50 Lecture4
 
D vs OWKN Language at LLnagoya
D vs OWKN Language at LLnagoyaD vs OWKN Language at LLnagoya
D vs OWKN Language at LLnagoya
 
Rust - Fernando Borretti
Rust - Fernando BorrettiRust - Fernando Borretti
Rust - Fernando Borretti
 
Format string vunerability
Format string vunerabilityFormat string vunerability
Format string vunerability
 
Functions
FunctionsFunctions
Functions
 

Similaire à Introduction to Python and Matplotlib

Python For Scientists
Python For ScientistsPython For Scientists
Python For Scientistsaeberspaecher
 
Lecture 5 – Computing with Numbers (Math Lib).pptx
Lecture 5 – Computing with Numbers (Math Lib).pptxLecture 5 – Computing with Numbers (Math Lib).pptx
Lecture 5 – Computing with Numbers (Math Lib).pptxjovannyflex
 
Lecture 5 – Computing with Numbers (Math Lib).pptx
Lecture 5 – Computing with Numbers (Math Lib).pptxLecture 5 – Computing with Numbers (Math Lib).pptx
Lecture 5 – Computing with Numbers (Math Lib).pptxjovannyflex
 
Introduction to Python Programming | InsideAIML
Introduction to Python Programming | InsideAIMLIntroduction to Python Programming | InsideAIML
Introduction to Python Programming | InsideAIMLVijaySharma802
 
unit (1)INTRODUCTION TO PYTHON course.pptx
unit (1)INTRODUCTION TO PYTHON course.pptxunit (1)INTRODUCTION TO PYTHON course.pptx
unit (1)INTRODUCTION TO PYTHON course.pptxusvirat1805
 
Introduction to phyton , important topic
Introduction to phyton , important topicIntroduction to phyton , important topic
Introduction to phyton , important topicakpgenious67
 
Python For Machine Learning
Python For Machine LearningPython For Machine Learning
Python For Machine LearningYounesCharfaoui
 
Introduction to python.pptx
Introduction to python.pptxIntroduction to python.pptx
Introduction to python.pptxpcjoshi02
 
Revision of the basics of python1 (1).pdf
Revision of the basics of python1 (1).pdfRevision of the basics of python1 (1).pdf
Revision of the basics of python1 (1).pdfoptimusnotch44
 
Chapter 1 Class 12 Computer Science Unit 1
Chapter 1 Class 12 Computer Science Unit 1Chapter 1 Class 12 Computer Science Unit 1
Chapter 1 Class 12 Computer Science Unit 1ssusera7a08a
 
Introduction to Python Programming
Introduction to Python ProgrammingIntroduction to Python Programming
Introduction to Python ProgrammingVijaySharma802
 
Machine Learning on Code - SF meetup
Machine Learning on Code - SF meetupMachine Learning on Code - SF meetup
Machine Learning on Code - SF meetupsource{d}
 
Python Course Basic
Python Course BasicPython Course Basic
Python Course BasicNaiyan Noor
 
Deep Learning, Scala, and Spark
Deep Learning, Scala, and SparkDeep Learning, Scala, and Spark
Deep Learning, Scala, and SparkOswald Campesato
 
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...DRVaibhavmeshram1
 
python-online&offline-training-in-kphb-hyderabad (1) (1).pdf
python-online&offline-training-in-kphb-hyderabad (1) (1).pdfpython-online&offline-training-in-kphb-hyderabad (1) (1).pdf
python-online&offline-training-in-kphb-hyderabad (1) (1).pdfKosmikTech1
 
Python Basics
Python BasicsPython Basics
Python BasicsPooja B S
 

Similaire à Introduction to Python and Matplotlib (20)

Python For Scientists
Python For ScientistsPython For Scientists
Python For Scientists
 
Lecture 5 – Computing with Numbers (Math Lib).pptx
Lecture 5 – Computing with Numbers (Math Lib).pptxLecture 5 – Computing with Numbers (Math Lib).pptx
Lecture 5 – Computing with Numbers (Math Lib).pptx
 
Lecture 5 – Computing with Numbers (Math Lib).pptx
Lecture 5 – Computing with Numbers (Math Lib).pptxLecture 5 – Computing with Numbers (Math Lib).pptx
Lecture 5 – Computing with Numbers (Math Lib).pptx
 
Introduction to Python Programming | InsideAIML
Introduction to Python Programming | InsideAIMLIntroduction to Python Programming | InsideAIML
Introduction to Python Programming | InsideAIML
 
unit (1)INTRODUCTION TO PYTHON course.pptx
unit (1)INTRODUCTION TO PYTHON course.pptxunit (1)INTRODUCTION TO PYTHON course.pptx
unit (1)INTRODUCTION TO PYTHON course.pptx
 
Introduction to phyton , important topic
Introduction to phyton , important topicIntroduction to phyton , important topic
Introduction to phyton , important topic
 
Python Basics
Python Basics Python Basics
Python Basics
 
Python For Machine Learning
Python For Machine LearningPython For Machine Learning
Python For Machine Learning
 
Introduction to python.pptx
Introduction to python.pptxIntroduction to python.pptx
Introduction to python.pptx
 
Python 3.pptx
Python 3.pptxPython 3.pptx
Python 3.pptx
 
Revision of the basics of python1 (1).pdf
Revision of the basics of python1 (1).pdfRevision of the basics of python1 (1).pdf
Revision of the basics of python1 (1).pdf
 
Chapter 1 Class 12 Computer Science Unit 1
Chapter 1 Class 12 Computer Science Unit 1Chapter 1 Class 12 Computer Science Unit 1
Chapter 1 Class 12 Computer Science Unit 1
 
Introduction to Python Programming
Introduction to Python ProgrammingIntroduction to Python Programming
Introduction to Python Programming
 
Machine Learning on Code - SF meetup
Machine Learning on Code - SF meetupMachine Learning on Code - SF meetup
Machine Learning on Code - SF meetup
 
Python Course Basic
Python Course BasicPython Course Basic
Python Course Basic
 
Deep Learning, Scala, and Spark
Deep Learning, Scala, and SparkDeep Learning, Scala, and Spark
Deep Learning, Scala, and Spark
 
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
 
Python
PythonPython
Python
 
python-online&offline-training-in-kphb-hyderabad (1) (1).pdf
python-online&offline-training-in-kphb-hyderabad (1) (1).pdfpython-online&offline-training-in-kphb-hyderabad (1) (1).pdf
python-online&offline-training-in-kphb-hyderabad (1) (1).pdf
 
Python Basics
Python BasicsPython Basics
Python Basics
 

Plus de François Bianco

Vulgarization poster about the Scanning Tunneling microscopy
Vulgarization poster about the Scanning Tunneling microscopyVulgarization poster about the Scanning Tunneling microscopy
Vulgarization poster about the Scanning Tunneling microscopyFrançois Bianco
 
Vulgarization poster about supraconductivity
Vulgarization poster about supraconductivityVulgarization poster about supraconductivity
Vulgarization poster about supraconductivityFrançois Bianco
 
Poster about atomic nanolines based on silicon only structures
Poster about atomic nanolines based on silicon only structuresPoster about atomic nanolines based on silicon only structures
Poster about atomic nanolines based on silicon only structuresFrançois Bianco
 
Poster about atomic nanolines
Poster about atomic nanolinesPoster about atomic nanolines
Poster about atomic nanolinesFrançois Bianco
 
Breakjunction for molecular contacting
Breakjunction for molecular contactingBreakjunction for molecular contacting
Breakjunction for molecular contactingFrançois Bianco
 
Thin epitaxial ferromagnetic metal films on GaAs(001) for spin injection and ...
Thin epitaxial ferromagnetic metal films on GaAs(001) for spin injection and ...Thin epitaxial ferromagnetic metal films on GaAs(001) for spin injection and ...
Thin epitaxial ferromagnetic metal films on GaAs(001) for spin injection and ...François Bianco
 
Introduction au microscope à effet tunnel
Introduction au microscope à effet tunnelIntroduction au microscope à effet tunnel
Introduction au microscope à effet tunnelFrançois Bianco
 
Presentation Prix Nobel 2007 sur la magnétorésistance gigantesque
Presentation Prix Nobel 2007 sur la magnétorésistance gigantesquePresentation Prix Nobel 2007 sur la magnétorésistance gigantesque
Presentation Prix Nobel 2007 sur la magnétorésistance gigantesqueFrançois Bianco
 
Présentation prix Nobel de physique 2012
Présentation prix Nobel de physique 2012Présentation prix Nobel de physique 2012
Présentation prix Nobel de physique 2012François Bianco
 
Fabrication and characterization of one-dimensional solid-state model systems...
Fabrication and characterization of one-dimensional solid-state model systems...Fabrication and characterization of one-dimensional solid-state model systems...
Fabrication and characterization of one-dimensional solid-state model systems...François Bianco
 

Plus de François Bianco (10)

Vulgarization poster about the Scanning Tunneling microscopy
Vulgarization poster about the Scanning Tunneling microscopyVulgarization poster about the Scanning Tunneling microscopy
Vulgarization poster about the Scanning Tunneling microscopy
 
Vulgarization poster about supraconductivity
Vulgarization poster about supraconductivityVulgarization poster about supraconductivity
Vulgarization poster about supraconductivity
 
Poster about atomic nanolines based on silicon only structures
Poster about atomic nanolines based on silicon only structuresPoster about atomic nanolines based on silicon only structures
Poster about atomic nanolines based on silicon only structures
 
Poster about atomic nanolines
Poster about atomic nanolinesPoster about atomic nanolines
Poster about atomic nanolines
 
Breakjunction for molecular contacting
Breakjunction for molecular contactingBreakjunction for molecular contacting
Breakjunction for molecular contacting
 
Thin epitaxial ferromagnetic metal films on GaAs(001) for spin injection and ...
Thin epitaxial ferromagnetic metal films on GaAs(001) for spin injection and ...Thin epitaxial ferromagnetic metal films on GaAs(001) for spin injection and ...
Thin epitaxial ferromagnetic metal films on GaAs(001) for spin injection and ...
 
Introduction au microscope à effet tunnel
Introduction au microscope à effet tunnelIntroduction au microscope à effet tunnel
Introduction au microscope à effet tunnel
 
Presentation Prix Nobel 2007 sur la magnétorésistance gigantesque
Presentation Prix Nobel 2007 sur la magnétorésistance gigantesquePresentation Prix Nobel 2007 sur la magnétorésistance gigantesque
Presentation Prix Nobel 2007 sur la magnétorésistance gigantesque
 
Présentation prix Nobel de physique 2012
Présentation prix Nobel de physique 2012Présentation prix Nobel de physique 2012
Présentation prix Nobel de physique 2012
 
Fabrication and characterization of one-dimensional solid-state model systems...
Fabrication and characterization of one-dimensional solid-state model systems...Fabrication and characterization of one-dimensional solid-state model systems...
Fabrication and characterization of one-dimensional solid-state model systems...
 

Dernier

Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomnelietumpap1
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Celine George
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxMaryGraceBautista27
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxDr.Ibrahim Hassaan
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxHumphrey A Beña
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONHumphrey A Beña
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...Nguyen Thanh Tu Collection
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxAshokKarra1
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfMr Bounab Samir
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxCarlos105
 

Dernier (20)

Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptxLEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choom
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptx
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptx
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptx
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
Raw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptxRaw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptx
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
 

Introduction to Python and Matplotlib

  • 1. Introduction to Python and Scientific Python Fran¸cois Bianco Unige 21th Dec 2011 Fran¸cois Bianco Introduction to Python
  • 2. Outlook 1 Python features and syntax 2 Examples, pylab, and iPython 3 Flat files examples Based on : Learn Python in 10 minutes : http://www.poromenos.org/tutorials/python Python documentation : http://docs.python.org/index.html Matplotlib : http://matplotlib.sourceforge.net/ Scipy : http://www.scipy.org/ Fran¸cois Bianco Introduction to Python
  • 3. Python is Strongly typed (i.e. types are enforced) Dynamically, implicitly typed (i.e. you don’t have to declare variables) Python is case sensitive (i.e. var and VAR are two different variables) object-oriented (i.e. everything is an object) able to handle memory by itself (i.e has a garbadge collector) Fran¸cois Bianco Introduction to Python
  • 4. Example Example l i s t = [1 ,1.1 ,1+1 j , ’ 1 ’ , True ] for element in l i s t : print element , type ( element ) , element==1.1 No mandatory statement termination character Blocks are specified by indentation (4 spaces, or 1 tab) Statements that expect an indentation level end in a colon “:” Values are assigned (in fact, objects are bound to names) with the equals sign “=” Equality testing is done using two equals signs “==” Fran¸cois Bianco Introduction to Python
  • 5. Data structures Three main data structures list = [1,2,3,4,5,6] are mutable tuples = (1,2,3,4,5,6) are unmutable dictionary = { ’key’:’value’, ’answer’:42, ’obj’:list } also called hash tables, access by key List and tuples are access by index : list[index] (see array slicing). Dictionary by key dictionary[’answer’]. Fran¸cois Bianco Introduction to Python
  • 6. Modules loading Classes and functions are stored in modules from math import s i n #only one f u n c t i o n s i n ( 0 . 3 ) import math #the whole module keeping namespace math . s i n ( 0 . 3 ) from math import * #the whole module cos ( 0 . 3 ) import m a t p l o t l i b as mptl #rename namespace mptl . c o n v e r t e r () Fran¸cois Bianco Introduction to Python
  • 7. Other features of Python Modern way of handling errors try : f i l e O b j = open ( ’ fileName . t x t ’ ) except IOError : print ErrorMessage Lambda functions f i t f u n c = lambda x , y : s q r t ( x/y ) f i t f u n c ( 4 . 5 , 2 . 3 ) Fran¸cois Bianco Introduction to Python
  • 8. Other features of Python Classes, functions... def functionName ( param , optionalParam=value ) : . . . class C h i l d C l a s s ( ParentClass ) : . . . Automatic documentation generation (with Doxygen) def toggleImages ( s e l f , event ) : ””” Toggle the two images according to the t r i g g e r event . param event Key or mouse event t r i g g e r i n g the f u n c t i o n ””” Fran¸cois Bianco Introduction to Python
  • 9. Flow control statements Example: Fibonnaci in a simple while loop a , b = 0 ,1 while b<10: print b a , b = b , a+b Easy variables assignation, and permutation, no extra variable needed. Fran¸cois Bianco Introduction to Python
  • 10. Array slicing Example: access to specific elements in an array x = arange (10) #c r e a t e a vector from 0 to 9 x #the whole vector x [ 0 ] #only the f i r s t element x [ 3 ] #the 3 rd element x [ −2] #the second l a t e s t element x [ 1 : 4 ] #elements from 1 to 4 x [ : 5 ] #elements up to 5 x [ −3:] #the three l a s t elements Fran¸cois Bianco Introduction to Python
  • 11. Array masking Example: create a mask on an array a = arange (10) mask = (( a % 2) == 0) a [ mask ] = 0 This sets all the even value in a to 0. Fran¸cois Bianco Introduction to Python
  • 12. Easy plot Example : plot with label and LATEX title p l o t ( arange (5)) x l a b e l ( ’ Index ’ ) y l a b e l ( ’Sum ’ ) t i t l e ( r ’ $sum { i =0}ˆ i n f t y i $ ’ ) Fran¸cois Bianco Introduction to Python
  • 13. Display matrix as an image Example : create an image from a matrix x = randn (20 ,20) #c r e a t e a random 20 x20 matrix imshow ( x ) #p i x e l s c a l e imshow ( x , extent =(0 ,1 ,0 ,1)) #add custom s c a l e Fran¸cois Bianco Introduction to Python
  • 14. Histogramm plot Example : create an histogramm plot mu, sigma = 100 , 15 x = mu + sigma * randn (10000) h i s t ( x ,100) Fran¸cois Bianco Introduction to Python
  • 15. Many plots Example : create two plots with legend t = arange (0 ,5 ,0.05) # Vect . 0 , 0 . 0 5 , 0 . 1 , . . . , 5 s1=s i n (2* pi * t ) s2=s1 *exp(−t ) p l o t ( t , s1 , ’g−−o ’ , t , s2 , ’ r : s ’ ) # custom s t y l e s legend (( ’ Sin wave ’ , ’Damped exp . ’ )) Fran¸cois Bianco Introduction to Python
  • 16. iPython Usefull magic commands in iPython help ( obj ) #Show help obj ? #Show doc s t r i n g obj ?? #Show source code #r e t u r n l a s t value %who #l i s t o b j e c t s %whos #d e t a i l l e d o b j e c t s l i s t %h i s t −n #h i s t o r y without l i n e number %exec In [ 4 : 7 ] #redo l i n e 4 to 7 %e d i t 4:7 #e d i t l i n e 4 to 7 in s c r i p t %run #launch a s c r i p t % p f i l e #show source f i l e content You want more of it ? Try %lsmagic Fran¸cois Bianco Introduction to Python
  • 17. Pro and cons Cons No GUI Documentation spread on different websites Requires basics programming skills Pro Easy to learn Work on every plateform (WinXP,Vista,MacOS,Linux,...) Could be bind to Gwyddion It’s a free software Fran¸cois Bianco Introduction to Python
  • 18. Other good reasons to learn Python Used by different universities and research centers : University of Montreal, Princeton University, Space Telescope Science Institute, Los Alamos National Laboratory, UC Berkeley, CERN, NASA ... If you want to look for a job in some “small” companies : Google, HP, IBM, Nokia, Thawte Consulting (SSL certificates), EA Games, Industrial Light & Magic (Hollywood), ... Fran¸cois Bianco Introduction to Python
  • 19. The end “There should be one – and preferably only one – obvious way to do it.” Tim Peters, The Zen of Python Fran¸cois Bianco Introduction to Python