Python Versus Matlab: Examples in Civil Engineering
Python Versus Matlab: Examples in Civil Engineering
Examples
Fedor Baart
Fedor Baart
Python versus Matlab: examples from geophysics to civil engineering
A bit about myself Learn a new language? What do people like? Examples
Introduction
Fedor Baart
Python versus Matlab: examples from geophysics to civil engineering
A bit about myself Learn a new language? What do people like? Examples
4 Examples
Fedor Baart
Python versus Matlab: examples from geophysics to civil engineering
A bit about myself Learn a new language? What do people like? Examples
Outline
4 Examples
Fedor Baart
Python versus Matlab: examples from geophysics to civil engineering
A bit about myself Learn a new language? What do people like? Examples
Senior consultant at
Deltares, coastal systems
and software data
integration
1 day a week at Hydraulic
Engineering at Delft 5 June 2013 Phd: Confidence in
University of Technology coastal forecasts
Fedor Baart
Python versus Matlab: examples from geophysics to civil engineering
A bit about myself Learn a new language? What do people like? Examples
Outline
4 Examples
Fedor Baart
Python versus Matlab: examples from geophysics to civil engineering
A bit about myself Learn a new language? What do people like? Examples
Fedor Baart
Python versus Matlab: examples from geophysics to civil engineering
A bit about myself Learn a new language? What do people like? Examples
Fedor Baart
Python versus Matlab: examples from geophysics to civil engineering
A bit about myself Learn a new language? What do people like? Examples
Fedor Baart
Python versus Matlab: examples from geophysics to civil engineering
A bit about myself Learn a new language? What do people like? Examples
Fedor Baart
Python versus Matlab: examples from geophysics to civil engineering
A bit about myself Learn a new language? What do people like? Examples
Scripting
Python Matlab
>>> 1 + 1 1 >> 1 + 1
>>> print ( " Hello World " ) >> disp ( Hello World ) ;
Fedor Baart
Python versus Matlab: examples from geophysics to civil engineering
A bit about myself Learn a new language? What do people like? Examples
Procedural
Python
Matlab
def add (a , b ) :
function total = add (a , b )
return a + b #
total = a + b
significant
end % ends the function 3
whitespace
Fedor Baart
Python versus Matlab: examples from geophysics to civil engineering
A bit about myself Learn a new language? What do people like? Examples
Functional
Python
Matlab
# anonymous function
# applied to each element 2
% apply anonymous function
>>> map ( lambda x : x **2 ,
% to each element 2
[1 ,2 ,3])
>> arrayfun ( @ ( x ) ( x ^2) , [1
[1 ,4 ,9]
2 3])
# recursive
ans =
# add (1 + reduce ( add ,
1 4 9
[2 ,3]) )
% reduce not in matlab
>>> reduce ( add , [1 ,2 ,3]) 7
6
Fedor Baart
Python versus Matlab: examples from geophysics to civil engineering
A bit about myself Learn a new language? What do people like? Examples
Object Oriented
Python Matlab
Fedor Baart
Python versus Matlab: examples from geophysics to civil engineering
A bit about myself Learn a new language? What do people like? Examples
Interface Oriented
Python
Fedor Baart
Python versus Matlab: examples from geophysics to civil engineering
A bit about myself Learn a new language? What do people like? Examples
Aspect Oriented
Python
@cache Matlab
def slow_calculation () :
time . sleep (100) 3 % Not used in
return 1+1 matlab
slow_calculation () # slow
slow_calculation () # fast
Fedor Baart
Python versus Matlab: examples from geophysics to civil engineering
A bit about myself Learn a new language? What do people like? Examples
Types
Python
Python
Types: Everything is an object
Types: Everything is an array
Type safety:
Weak dynamic, typed
# strong , dynamic
>> x = 1
>>> x = 1
>> x = a
>>> x = a
>> x = 1 + a
>>> x = 1 + a 4
98
TypeError
Fedor Baart
Python versus Matlab: examples from geophysics to civil engineering
A bit about myself Learn a new language? What do people like? Examples
Outline
4 Examples
Fedor Baart
Python versus Matlab: examples from geophysics to civil engineering
A bit about myself Learn a new language? What do people like? Examples
Fedor Baart
Python versus Matlab: examples from geophysics to civil engineering
A bit about myself Learn a new language? What do people like? Examples
python
science
matlab
geospatial
engineering
web
science
system
games
Fedor Baart
Python versus Matlab: examples from geophysics to civil engineering
A bit about myself Learn a new language? What do people like? Examples
scientists programmers
less more
abstract abstract
FOTRAN / C
Matlab
Python / Ruby
Java / C#
Fedor Baart
Python versus Matlab: examples from geophysics to civil engineering
A bit about myself Learn a new language? What do people like? Examples
python
help ( function ) 1
Fedor Baart
Python versus Matlab: examples from geophysics to civil engineering
A bit about myself Learn a new language? What do people like? Examples
15 Spyder
Fedor Baart
Python versus Matlab: examples from geophysics to civil engineering
A bit about myself Learn a new language? What do people like? Examples
3 emacs
4 PyCharm
15 Spyder
Fedor Baart
Python versus Matlab: examples from geophysics to civil engineering
A bit about myself Learn a new language? What do people like? Examples
Screenshot
Most popular python IDE (@SO)
new ipython notebook
1 vim
2 PyDev
3 emacs
4 PyCharm
15 Spyder
Fedor Baart
Python versus Matlab: examples from geophysics to civil engineering
A bit about myself Learn a new language? What do people like? Examples
Python Matlab
Startup do nothing and shutdown Startup do nothing and shutdown
time. time.
$time python -c " pass " $ time matlab -r exit 1
real 0 m0 .038 s real 1 m8 .891 s
user 0 m0 .022 s user 0 m11 .889 s
sys 0 m0 .012 s 4 sys 0 m3 .184 s
Other languages
C: 0.000s, Java: 0.3s, Perl 0.001s, Bash 0.001s
Fedor Baart
Python versus Matlab: examples from geophysics to civil engineering
A bit about myself Learn a new language? What do people like? Examples
Matlab
Python
>> x = zeros (1000) ;
>>> timeit . timeit ( a = x . dot ( 1 >> tic ; for i =1:10; a = x * x ; end
x ) number =10) ; toc
1. 594820 97 62 57 324 2 Elapsed time is 1.796690 3
seconds .
Fedor Baart
Python versus Matlab: examples from geophysics to civil engineering
A bit about myself Learn a new language? What do people like? Examples
Outline
4 Examples
Fedor Baart
Python versus Matlab: examples from geophysics to civil engineering
A bit about myself Learn a new language? What do people like? Examples
BMI
fortran + web
Fedor Baart
Python versus Matlab: examples from geophysics to civil engineering
A bit about myself Learn a new language? What do people like? Examples
Kustviewer
data + gis + web
Fedor Baart
Python versus Matlab: examples from geophysics to civil engineering
A bit about myself Learn a new language? What do people like? Examples
Argus
notebook (calculator) + computer vision
Fedor Baart
Python versus Matlab: examples from geophysics to civil engineering
A bit about myself Learn a new language? What do people like? Examples
Leap
Interaction + 2d, 3d plotting
Fedor Baart
Python versus Matlab: examples from geophysics to civil engineering