Part VI. Scientific Computing in Python. Tobias Neckel: Scripting with Bash and Python Compact Max-Planck, February 16-26,

Size: px
Start display at page:

Download "Part VI. Scientific Computing in Python. Tobias Neckel: Scripting with Bash and Python Compact Max-Planck, February 16-26,"

Transcription

1 Part VI Scientific Computing in Python Compact Max-Planck, February 16-26,

2 More on Maths Module math Constants pi and e Functions that operate on int and float All return values float ceil (x) floor (x) exp (x) fabs ( x) # same as globally defined abs () ldexp (x, i) # x * 2** i log (x [, base ]) log10 (x) # == log (x, 10) modf ( x) # ( fractional, integer part ) pow (x, y) # x**y sqrt (x) Compact Max-Planck, February 16-26,

3 Module math (2) Trigonometric functions assume radians cos (x); cosh (x); acos (x) sin (x);... tan (x);... degrees (x) # rad -> deg radians (x) # deg -> rad Compact Max-Planck, February 16-26,

4 Module math (2) Trigonometric functions assume radians cos (x); cosh (x); acos (x) sin (x);... tan (x);... degrees (x) # rad -> deg radians (x) # deg -> rad inf/nan float (" inf ") float ("-inf ") float (" nan ") Compact Max-Planck, February 16-26,

5 Module math (2) Trigonometric functions assume radians cos (x); cosh (x); acos (x) sin (x);... tan (x);... degrees (x) # rad -> deg radians (x) # deg -> rad inf/nan float (" inf ") float ("-inf ") float (" nan ") Use module cmath for complex numbers Compact Max-Planck, February 16-26,

6 Now to Real Maths... Standard sequence types (list, tuple,... ) Can be used as arrays Can contain different types of objects Very flexible, but slow Loops are not very efficient either For efficient scientific computing, other datatypes and methods required Compact Max-Planck, February 16-26,

7 Now to Real Maths... Standard sequence types (list, tuple,... ) Can be used as arrays Can contain different types of objects Very flexible, but slow Loops are not very efficient either For efficient scientific computing, other datatypes and methods required Modules NumPy Matplotlib SciPy Compact Max-Planck, February 16-26,

8 NumPy Compact Max-Planck, February 16-26,

9 Module numpy Homogeneous arrays NumPy provides arbitrary-dimensional homogeneous arrays Example from numpy import * a = array ([[1,2,3],[4,5,6]]) print a type (a) a. shape print a [0,2] a [0,2] = -1 b = a*2 print b Compact Max-Planck, February 16-26,

10 Array creation Create from (nested) sequence type Direct access with method [] a = array ([1,2,3,4,5,6,7,8]) a [1] a = array ([[1,2,3,4],[5,6,7,8]]) a [1,1] a = array ([[[1,2],[3,4]],[[5,6],[7,8]]]) a [1,1,1] Compact Max-Planck, February 16-26,

11 Array creation Create from (nested) sequence type Direct access with method [] a = array ([1,2,3,4,5,6,7,8]) a [1] a = array ([[1,2,3,4],[5,6,7,8]]) a [1,1] a = array ([[[1,2],[3,4]],[[5,6],[7,8]]]) a [1,1,1] Properties of arrays a. ndim # number of dimensions a. shape # dimensions a. size # number of elements a. dtype # data type a. itemsize # number of bytes Compact Max-Planck, February 16-26,

12 Data Types Exact, C/C++-motivated type of array elements can be specified Otherwise, defaults are used Some types (different storage requirements): int_, int8, int16, int32, int64, float_, float8, float16, float32, float64, complex_, complex64, bool_, character, object_ Standard python type names result in default behaviour array ([[1,2,3],[4,5,6]], dtype = int ) array ([[1,2,3],[4,5,6]], dtype = complex ) array ([[1,2,3],[4,5,6]], dtype = int8 ) array ([[1,2,3],[4,5,1000]], dtype = int8 ) # wrong array ([[1,2,3],[4,5, "hi"]], dtype = object ) Compact Max-Planck, February 16-26,

13 Create Arrays (Some) default matrices (optional parameter: dtype) arange ([a,] b [, stride ]) # as range, 1D zeros ( (3,4) ) ones ( (1,3,4) ) empty ( (3,4) ) # uninitialized ( fast ) linspace (a, b [, n]) # n equidistant in [a, b] logspace (a, b [, n]) # 10** a to 10** b identity (n) # 2d fromfunction ( lambda i,j: i+j, (3,4), dtype = int ) def f(i,j): return i+j fromfunction (f, (3,4), dtype = int ) Compact Max-Planck, February 16-26,

14 Manipulate Arrays Reshaping arrays a = arange (12) b = a. reshape ((3,4)) a. resize ((3,4)) # in - place! a. transpose () a. flatten () # Example use - case : a = arange (144) a. resize ((12,12)) Compact Max-Planck, February 16-26,

15 Create Arrays (2) Create/Copy from existing data a = arange (12); a. resize ((3,4)) copy (a) diag (a); tril (a); triu (a) empty_like ( a) # copy shape zeros_like (a) ones_like (a) a = loadtxt (" matrix. txt ") # fromfile () if binary # plenty of options : comments, delim., usecols,... Compact Max-Planck, February 16-26,

16 Create Arrays (2) Create/Copy from existing data a = arange (12); a. resize ((3,4)) copy (a) diag (a); tril (a); triu (a) empty_like ( a) # copy shape zeros_like (a) ones_like (a) a = loadtxt (" matrix. txt ") # fromfile () if binary # plenty of options : comments, delim., usecols,... Matrix output a. tolist () savetxt (" matrix. txt ", a) # tofile () if binary Compact Max-Planck, February 16-26,

17 Array Access and Manipulation Typical slicing operations can be used Separate dimensions by comma a = arange (20); a. resize ((4,5)) a [1] a [1:2,:] a [:,::2] a [::2,::2] a [::2,::2] = [[0, -2, -4],[ -10, -12, -14]] a [1::2,1::2] = -1*a [1::2,1::2] Compact Max-Planck, February 16-26,

18 Array Access and Manipulation Typical slicing operations can be used Separate dimensions by comma a = arange (20); a. resize ((4,5)) a [1] a [1:2,:] a [:,::2] a [::2,::2] a [::2,::2] = [[0, -2, -4],[ -10, -12, -14]] a [1::2,1::2] = -1*a [1::2,1::2] Selective access a[a > 3] a[a > 3] = -1 Compact Max-Planck, February 16-26,

19 Array Access Iterating over entries for row in a: print row b = arange (30); b. resize ((2,3,4)) for row in b: for col in row : print col for entry in a. flat : print entry Compact Max-Planck, February 16-26,

20 Computing with Arrays Fast built-in methods working on arrays a = arange (12); a. resize ((3,4)) 3*a a **2 a+a^2 sin (a) sqrt (a) prod (a) sum (a) it = transpose (a) x = array ([1,2,3]) y = array ([10,20,30]) inner (x, y) dot (it, x) cross (x,y) Compact Max-Planck, February 16-26,

21 Computing with Arrays There is much more... var () cov () std () mean () median () min () max () svd () tensordot ()... Compact Max-Planck, February 16-26,

22 Computing with Arrays There is much more... var () cov () std () mean () median () min () max () svd () tensordot ()... Matrices (with mat) are subclasses of ndarray, but strictly two-dimensional, with additional attributes m = mat (a) m.t # transpose m.i # inverse m.a # as 2d array m. H # conjugate transpose Compact Max-Planck, February 16-26,

23 Submodules Module numpy.random Draw from plenty of different distributions More powerful than module random Work on and return arrays from numpy. random import * binomial (10, 0.5) # 10 trials, success 50% binomial (10, 0.5, 15) randint (0, 10, 15) # [0,10), int rand () # [0,1) rand (3,4) # (3 x4) array Compact Max-Planck, February 16-26,

24 Submodules (2) Module numpy.linalg Core linear algebra tools norm (a); norm (x) inv (a) solve (a, b) # LAPACK LU decomp. det (a) eig (a) cholesky (a) Compact Max-Planck, February 16-26,

25 Submodules (2) Module numpy.linalg Core linear algebra tools norm (a); norm (x) inv (a) solve (a, b) # LAPACK LU decomp. det (a) eig (a) cholesky (a) Module numpy.fft Fourier transforms Compact Max-Planck, February 16-26,

26 Submodules (2) Module numpy.linalg Core linear algebra tools norm (a); norm (x) inv (a) solve (a, b) # LAPACK LU decomp. det (a) eig (a) cholesky (a) Module numpy.fft Fourier transforms There is more... Compact Max-Planck, February 16-26,

27 Version Mania Current Situation SciPy Matplotlib NumPy pylab IPython python Compact Max-Planck, February 16-26,

28 Version Mania Problems: Numpy, scipy, pylab, ipython and matplotlib often used simultaneously The packages depend on each other (matplotlib uses numpy arrays, e.g.) Depending on OS (version), different packages may have to be installed (i.e. the module name in import command may be different!). Compact Max-Planck, February 16-26,

29 Version Mania Problems: Numpy, scipy, pylab, ipython and matplotlib often used simultaneously The packages depend on each other (matplotlib uses numpy arrays, e.g.) Depending on OS (version), different packages may have to be installed (i.e. the module name in import command may be different!). Vision: All in one (new) module PyLab! exists as unofficial package Attention Name: again pylab! Compact Max-Planck, February 16-26,

30 Matplotlib Compact Max-Planck, February 16-26,

31 Matplotlib What is it? Object-oriented library for plotting 2D Designed to be similar to the matlab plotting functionality Designed to plot scientific data, built on numpy datastructures Compact Max-Planck, February 16-26,

32 Several Ways to do the Same python/ipython interactive > ipython import scipy, matplotlib. pylab x = scipy. randn (10000) matplotlib. pylab. hist (x, 100) Compact Max-Planck, February 16-26,

33 Several Ways to do the Same python/ipython interactive > ipython import scipy, matplotlib. pylab x = scipy. randn (10000) matplotlib. pylab. hist (x, 100) > ipython import numpy. random, matplotlib. pylab x = numpy. random. randn (10000) matplotlib. pylab. hist (x, 100) Compact Max-Planck, February 16-26,

34 Several Ways to do the Same python/ipython interactive > ipython import scipy, matplotlib. pylab x = scipy. randn (10000) matplotlib. pylab. hist (x, 100) > ipython import numpy. random, matplotlib. pylab x = numpy. random. randn (10000) matplotlib. pylab. hist (x, 100) ipython in pylab mode > ipython - pylab x = randn (10000) hist (x, 100) Compact Max-Planck, February 16-26,

35 Example - First Plot partially taken from from pylab import * x = arange (0.0, 2* pi, 0.01) y = sin (x) plot (x, y, linewidth =4) plot (x,y) xlabel ( Label for x axis ) ylabel ( Label for y axis ) title ( Simple plot of sin ) grid ( True ) show () Compact Max-Planck, February 16-26,

36 Example Using Subplots from pylab import * def f(t): s1 = cos (2* pi*t) e1 = exp (-t) return multiply (s1,e1) t1 = arange (0.0, 5.0, 0.1) t2 = arange (0.0, 5.0, 0.02) t3 = arange (0.0, 2.0, 0.01) show () # gives error but helps ; -) subplot (2,1,1) # rows, columns, which to show plot (t1, f(t1), go, t2, f(t2), k-- ) subplot (2,1,2) plot (t3, cos (2* pi*t3), r. ) Compact Max-Planck, February 16-26,

37 Example Using Subplots # previous slide continued subplot (2,1,1) grid ( True ) title ( A tale of 2 subplots ) ylabel ( Damped oscillation ) subplot (2,1,2) grid ( True ) xlabel ( time (s) ) ylabel ( Undamped ) Compact Max-Planck, February 16-26,

38 Example - Histogram # start ipython - pylab or use imports : from matplotlib. mlab import * from matplotlib. pyplot import * from numpy import * mu, sigma = 100, 15 x = mu + sigma * random. randn (10000) n, bins, patches = hist (x, 50, normed =1, \ facecolor = green, alpha =0.75) # add a best fit line y = normpdf ( bins, mu, sigma ) plot (bins, y, r--, linewidth =1) axis ([40, 160, 0, 0.03]) plt. show () Compact Max-Planck, February 16-26,

39 SciPy Compact Max-Planck, February 16-26,

40 More than NumPy? SciPy depends on NumPy Built to work on NumPy arrays Providing functionality for mathematics, science and engineering Still under development NumPy is mostly about (N-dimensional) arrays SciPy comprises a large number of tools using these arrays SciPy includes the NumPy functionality (only one import necessary) A lot more libraries for scientific computing are available, some of them using NumPy and SciPy Here, just a short overview will be given for more material (incl. the content of the following slides) Compact Max-Planck, February 16-26,

41 SciPy Organisation - Subpackages cluster Clustering algorithms constants Physical and mathematical constants fftpack Fast Fourier Transform routines integrate Integration and ordinary differential equation solvers interpolate Interpolation and smoothing splines io Input and Output linalg Linear algebra maxentropy Maximum entropy methods ndimage N-dimensional image processing odr Orthogonal distance regression optimize Optimization and root-finding routines signal Signal processing sparse Sparse matrices and associated routines spatial Spatial data structures and algorithms special Special functions stats Statistical distributions and functions weave C/C++ integration Compact Max-Planck, February 16-26,

42 Special Functions Airy functions Elliptic functions Bessel functions (+ Zeros, Integrals, Derivatives, Spherical, Ricatti-) Struve functions A large number of statistical functions Gamma functions Legendre functions Orthogonal polynomials (Legendre, Chebyshev, Jacobi,...) Hypergeometric functios parabolic cylinder functions Mathieu functions Spheroidal wave functions Kelvin functions... Compact Max-Planck, February 16-26,

43 Example: Interpolation - Linear import numpy as np import matplotlib. pyplot as plt from scipy import interpolate x = np. arange (0, 2.25* np.pi, np.pi /4) y = np.sin (x) f = interpolate. interp1d (x, y) xnew = np. arange (0,2.0* np.pi,np.pi /100) plt. plot (x,y, o,xnew,f( xnew ), - ) plt. title ( Linear interpolation ) plt. show () Compact Max-Planck, February 16-26,

44 Example: Interpolation - Cubic Spline import numpy as np import matplotlib. pyplot as plt from scipy import interpolate x = np. arange (0, 2.25* np.pi, np.pi /4) y = np.sin (x) spline = interpolate. splrep (x,y,s =0) xnew = np. arange (0,2.02* np.pi,np.pi /50) ynew = interpolate. splev ( xnew, spline ) plt. plot (x,y, o,xnew, ynew ) plt. legend ([ Linear, Cubic Spline ]) plt. axis ([ -0.05,6.33, -1.05,1.05]) plt. title ( Cubic - spline interpolation ) plt. show () Compact Max-Planck, February 16-26,

Part VI. Scientific Computing in Python. Alfredo Parra : Scripting with Python Compact Max-PlanckMarch 6-10,

Part VI. Scientific Computing in Python. Alfredo Parra : Scripting with Python Compact Max-PlanckMarch 6-10, Part VI Scientific Computing in Python Compact Course @ Max-PlanckMarch 6-10, 2017 63 Doing maths in Python Standard sequence types (list, tuple,... ) Can be used as arrays Can contain different types

More information

Python Crash Course Numpy, Scipy, Matplotlib

Python Crash Course Numpy, Scipy, Matplotlib Python Crash Course Numpy, Scipy, Matplotlib That is what learning is. You suddenly understand something you ve understood all your life, but in a new way. Doris Lessing Steffen Brinkmann Max-Planck-Institut

More information

LECTURE 22. Numerical and Scientific Packages

LECTURE 22. Numerical and Scientific Packages LECTURE 22 Numerical and Scientific Packages NUMERIC AND SCIENTIFIC APPLICATIONS As you might expect, there are a number of third-party packages available for numerical and scientific computing that extend

More information

NumPy is suited to many applications Image processing Signal processing Linear algebra A plethora of others

NumPy is suited to many applications Image processing Signal processing Linear algebra A plethora of others Introduction to NumPy What is NumPy NumPy is a Python C extension library for array-oriented computing Efficient In-memory Contiguous (or Strided) Homogeneous (but types can be algebraic) NumPy is suited

More information

NumPy and SciPy. Shawn T. Brown Director of Public Health Applications Pittsburgh Supercomputing Center Pittsburgh Supercomputing Center

NumPy and SciPy. Shawn T. Brown Director of Public Health Applications Pittsburgh Supercomputing Center Pittsburgh Supercomputing Center NumPy and SciPy Shawn T. Brown Director of Public Health Applications Pittsburgh Supercomputing Center 2012 Pittsburgh Supercomputing Center What are NumPy and SciPy NumPy and SciPy are open-source add-on

More information

LECTURE 19. Numerical and Scientific Packages

LECTURE 19. Numerical and Scientific Packages LECTURE 19 Numerical and Scientific Packages NUMERICAL AND SCIENTIFIC APPLICATIONS As you might expect, there are a number of third-party packages available for numerical and scientific computing that

More information

CSC Advanced Scientific Computing, Fall Numpy

CSC Advanced Scientific Computing, Fall Numpy CSC 223 - Advanced Scientific Computing, Fall 2017 Numpy Numpy Numpy (Numerical Python) provides an interface, called an array, to operate on dense data buffers. Numpy arrays are at the core of most Python

More information

Phys Techniques of Radio Astronomy Part 1: Python Programming LECTURE 3

Phys Techniques of Radio Astronomy Part 1: Python Programming LECTURE 3 Phys 60441 Techniques of Radio Astronomy Part 1: Python Programming LECTURE 3 Tim O Brien Room 3.214 Alan Turing Building tim.obrien@manchester.ac.uk Tuples Lists and strings are examples of sequences.

More information

Introduction to NumPy

Introduction to NumPy Lab 3 Introduction to NumPy Lab Objective: NumPy is a powerful Python package for manipulating data with multi-dimensional vectors. Its versatility and speed makes Python an ideal language for applied

More information

Introduction to Octave/Matlab. Deployment of Telecommunication Infrastructures

Introduction to Octave/Matlab. Deployment of Telecommunication Infrastructures Introduction to Octave/Matlab Deployment of Telecommunication Infrastructures 1 What is Octave? Software for numerical computations and graphics Particularly designed for matrix computations Solving equations,

More information

Fundamentals of MATLAB Usage

Fundamentals of MATLAB Usage 수치해석기초 Fundamentals of MATLAB Usage 2008. 9 담당교수 : 주한규 joohan@snu.ac.kr, x9241, Rm 32-205 205 원자핵공학과 1 MATLAB Features MATLAB: Matrix Laboratory Process everything based on Matrix (array of numbers) Math

More information

MATH 3511 Basics of MATLAB

MATH 3511 Basics of MATLAB MATH 3511 Basics of MATLAB Dmitriy Leykekhman Spring 2012 Topics Sources. Entering Matrices. Basic Operations with Matrices. Build in Matrices. Build in Scalar and Matrix Functions. if, while, for m-files

More information

MATH 5520 Basics of MATLAB

MATH 5520 Basics of MATLAB MATH 5520 Basics of MATLAB Dmitriy Leykekhman Spring 2011 Topics Sources. Entering Matrices. Basic Operations with Matrices. Build in Matrices. Build in Scalar and Matrix Functions. if, while, for m-files

More information

Introduction to Matlab

Introduction to Matlab Introduction to Matlab By:Mohammad Sadeghi *Dr. Sajid Gul Khawaja Slides has been used partially to prepare this presentation Outline: What is Matlab? Matlab Screen Basic functions Variables, matrix, indexing

More information

An introduction to scientific programming with. Session 3: Scientific Python

An introduction to scientific programming with. Session 3: Scientific Python An introduction to scientific programming with Session 3: Scientific Python A Python program relevant to your research put course material into practice opportunity to become familiar with Python requirement

More information

IAP Python - Lecture 4

IAP Python - Lecture 4 IAP Python - Lecture 4 Andrew Farrell MIT SIPB January 13, 2011 NumPy, SciPy, and matplotlib are a collection of modules that together are trying to create the functionality of MATLAB in Python. Andrew

More information

NumPy quick reference

NumPy quick reference John W. Shipman 2016-05-30 12:28 Abstract A guide to the more common functions of NumPy, a numerical computation module for the Python programming language. This publication is available in Web form1 and

More information

SciPy. scipy [www.scipy.org and links on course web page] scipy arrays

SciPy. scipy [www.scipy.org and links on course web page] scipy arrays SciPy scipy [www.scipy.org and links on course web page] - scipy is a collection of many useful numerical algorithms (numpy is the array core) - Python wrappers around compiled libraries and subroutines

More information

MATLAB and Numerical Analysis

MATLAB and Numerical Analysis School of Mechanical Engineering Pusan National University dongwoonkim@pusan.ac.kr Teaching Assistant 김동운 dongwoonkim@pusan.ac.kr 윤종희 jongheeyun@pusan.ac.kr Lab office: 통합기계관 120호 ( 510-3921) 방사선영상연구실홈페이지

More information

Scientific Programming. Lecture A08 Numpy

Scientific Programming. Lecture A08 Numpy Scientific Programming Lecture A08 Alberto Montresor Università di Trento 2018/10/25 Acknowledgments: Stefano Teso, Documentation http://disi.unitn.it/~teso/courses/sciprog/python_appendices.html https://docs.scipy.org/doc/numpy-1.13.0/reference/

More information

CME 193: Introduction to Scientific Python Lecture 5: Numpy, Scipy, Matplotlib

CME 193: Introduction to Scientific Python Lecture 5: Numpy, Scipy, Matplotlib CME 193: Introduction to Scientific Python Lecture 5: Numpy, Scipy, Matplotlib Sven Schmit stanford.edu/~schmit/cme193 5: Numpy, Scipy, Matplotlib 5-1 Contents Second part of course Numpy Scipy Matplotlib

More information

NumPy and SciPy. Lab Objective: Create and manipulate NumPy arrays and learn features available in NumPy and SciPy.

NumPy and SciPy. Lab Objective: Create and manipulate NumPy arrays and learn features available in NumPy and SciPy. Lab 2 NumPy and SciPy Lab Objective: Create and manipulate NumPy arrays and learn features available in NumPy and SciPy. Introduction NumPy and SciPy 1 are the two Python libraries most used for scientific

More information

An introduction to scientific programming with. Session 3: Scientific Python

An introduction to scientific programming with. Session 3: Scientific Python An introduction to scientific programming with Session 3: Scientific Python A Python program relevant to your research put course material into practice opportunity to become familiar with Python requirement

More information

Problem Based Learning 2018

Problem Based Learning 2018 Problem Based Learning 2018 Introduction to Machine Learning with Python L. Richter Department of Computer Science Technische Universität München Monday, Jun 25th L. Richter PBL 18 1 / 21 Overview 1 2

More information

User-Defined Function

User-Defined Function ENGR 102-213 (Socolofsky) Week 11 Python scripts In the lecture this week, we are continuing to learn powerful things that can be done with userdefined functions. In several of the examples, we consider

More information

Datenanalyse (PHY231) Herbstsemester 2017

Datenanalyse (PHY231) Herbstsemester 2017 Datenanalyse (PHY231) Herbstsemester 2017 A short pylab repetition 22/09/2017 An important part of the exercises for this course involves programming in python / pylab. We assume that you have completed

More information

Tentative NumPy Tutorial

Tentative NumPy Tutorial Page 1 of 30 Tentative NumPy Tutorial Please do not hesitate to click the edit button. You will need to create a User Account first. Contents 1. Prerequisites 2. The Basics 1. An example 2. Array Creation

More information

Introduction to Scientific Computing with Python, part two.

Introduction to Scientific Computing with Python, part two. Introduction to Scientific Computing with Python, part two. M. Emmett Department of Mathematics University of North Carolina at Chapel Hill June 20 2012 The Zen of Python zen of python... fire up python

More information

Grad Refresher Series Python. Marius Muja September 28, 2011

Grad Refresher Series Python. Marius Muja September 28, 2011 Grad Refresher Series 2011 Python Marius Muja mariusm@cs.ubc.ca September 28, 2011 The Python Programming Language Interpreted - but can have modules written in C/C++ Dynamically, strongly typed dynamically

More information

CME 193: Introduction to Scientific Python Lecture 6: Numpy, Scipy, Matplotlib

CME 193: Introduction to Scientific Python Lecture 6: Numpy, Scipy, Matplotlib CME 193: Introduction to Scientific Python Lecture 6: Numpy, Scipy, Matplotlib Nolan Skochdopole stanford.edu/class/cme193 6: Numpy, Scipy, Matplotlib 6-1 Contents Homeworks and Project Numpy Scipy Matplotlib

More information

ENGR Fall Exam 1

ENGR Fall Exam 1 ENGR 1300 Fall 01 Exam 1 INSTRUCTIONS: Duration: 60 minutes Keep your eyes on your own work! Keep your work covered at all times! 1. Each student is responsible for following directions. Read carefully..

More information

Some elements for Matlab programming

Some elements for Matlab programming Some elements for Matlab programming Nathalie Thomas 2018 2019 Matlab, which stands for the abbreviation of MATrix LABoratory, is one of the most popular language for scientic computation. The classical

More information

ENGR (Socolofsky) Week 07 Python scripts

ENGR (Socolofsky) Week 07 Python scripts ENGR 102-213 (Socolofsky) Week 07 Python scripts A couple programming examples for this week are embedded in the lecture notes for Week 7. We repeat these here as brief examples of typical array-like operations

More information

Introduction to MATLAB. Computational Probability and Statistics CIS 2033 Section 003

Introduction to MATLAB. Computational Probability and Statistics CIS 2033 Section 003 Introduction to MATLAB Computational Probability and Statistics CIS 2033 Section 003 About MATLAB MATLAB (MATrix LABoratory) is a high level language made for: Numerical Computation (Technical computing)

More information

The SciPy Stack. Jay Summet

The SciPy Stack. Jay Summet The SciPy Stack Jay Summet May 1, 2014 Outline Numpy - Arrays, Linear Algebra, Vector Ops MatPlotLib - Data Plotting SciPy - Optimization, Scientific functions TITLE OF PRESENTATION 2 What is Numpy? 3rd

More information

Interactive Computing with Matlab. Gerald W. Recktenwald Department of Mechanical Engineering Portland State University

Interactive Computing with Matlab. Gerald W. Recktenwald Department of Mechanical Engineering Portland State University Interactive Computing with Matlab Gerald W. Recktenwald Department of Mechanical Engineering Portland State University gerry@me.pdx.edu Starting Matlab Double click on the Matlab icon, or on unix systems

More information

Why NumPy / SciPy? NumPy / SciPy / Matplotlib. A Tour of NumPy. Initializing a NumPy array

Why NumPy / SciPy? NumPy / SciPy / Matplotlib. A Tour of NumPy. Initializing a NumPy array NumPy / SciPy / Matplotlib NumPy is an extension to Python adding support for arrays and matrices, along with a large library of high-level mathematical functions to operate on them. SciPy is a library

More information

A0B17MTB Matlab. Part #2. Miloslav Čapek Viktor Adler, Pavel Valtr. Department of Electromagnetic Field B2-634, Prague

A0B17MTB Matlab. Part #2. Miloslav Čapek Viktor Adler, Pavel Valtr. Department of Electromagnetic Field B2-634, Prague 017MT Matlab Part #2 Miloslav Čapek miloslav.capek@fel.cvut.cz Viktor dler, Pavel Valtr Department of Electromagnetic Field 2-634, Prague Learning how to Complex numbers Matrix creation Operations with

More information

MATLAB Tutorial. Mohammad Motamed 1. August 28, generates a 3 3 matrix.

MATLAB Tutorial. Mohammad Motamed 1. August 28, generates a 3 3 matrix. MATLAB Tutorial 1 1 Department of Mathematics and Statistics, The University of New Mexico, Albuquerque, NM 87131 August 28, 2016 Contents: 1. Scalars, Vectors, Matrices... 1 2. Built-in variables, functions,

More information

Numerical Calculations

Numerical Calculations Fundamentals of Programming (Python) Numerical Calculations Sina Sajadmanesh Sharif University of Technology Some slides have been adapted from Scipy Lecture Notes at http://www.scipy-lectures.org/ Outline

More information

Python for Scientists

Python for Scientists High level programming language with an emphasis on easy to read and easy to write code Includes an extensive standard library We use version 3 History: Exists since 1991 Python 3: December 2008 General

More information

The Python Programming Language

The Python Programming Language Python Marius Muja The Python Programming Language Interpreted - but can have modules written in C/C++ Dynamically but strongly typed dynamically typed - no need to declare variable types strongly typed

More information

Day 15: Science Code in Python

Day 15: Science Code in Python Day 15: Science Code in Python 1 Turn In Homework 2 Homework Review 3 Science Code in Python? 4 Custom Code vs. Off-the-Shelf Trade-offs Costs (your time vs. your $$$) Your time (coding vs. learning) Control

More information

Introduction to NumPy

Introduction to NumPy Introduction to NumPy Travis E. Oliphant Electrical Engineering Brigham Young University Provo, Utah http://numeric.scipy.org NumPy NumPy An N dimensional homogeneous array object Universal element by

More information

Matlab course at. P. Ciuciu 1,2. 1: CEA/NeuroSpin/LNAO 2: IFR49

Matlab course at. P. Ciuciu 1,2. 1: CEA/NeuroSpin/LNAO 2: IFR49 Matlab course at NeuroSpin P. Ciuciu 1,2 philippe.ciuciu@cea.fr www.lnao.fr 1: CEA/NeuroSpin/LNAO 2: IFR49 Feb 26, 2009 Outline 2/9 Lesson0: Getting started: environment,.m and.mat files Lesson I: Scalar,

More information

ENGR Fall Exam 1

ENGR Fall Exam 1 ENGR 13100 Fall 2012 Exam 1 INSTRUCTIONS: Duration: 60 minutes Keep your eyes on your own work! Keep your work covered at all times! 1. Each student is responsible for following directions. Read carefully.

More information

A very brief Matlab introduction

A very brief Matlab introduction A very brief Matlab introduction Siniša Krajnović January 24, 2006 This is a very brief introduction to Matlab and its purpose is only to introduce students of the CFD course into Matlab. After reading

More information

Getting Started with MATLAB

Getting Started with MATLAB Getting Started with MATLAB Math 315, Fall 2003 Matlab is an interactive system for numerical computations. It is widely used in universities and industry, and has many advantages over languages such as

More information

Course May 18, Advanced Computational Physics. Course Hartmut Ruhl, LMU, Munich. People involved. SP in Python: 3 basic points

Course May 18, Advanced Computational Physics. Course Hartmut Ruhl, LMU, Munich. People involved. SP in Python: 3 basic points May 18, 2017 3 I/O 3 I/O 3 I/O 3 ASC, room A 238, phone 089-21804210, email hartmut.ruhl@lmu.de Patrick Böhl, ASC, room A205, phone 089-21804640, email patrick.boehl@physik.uni-muenchen.de. I/O Scientific

More information

Introductory Scientific Computing with Python

Introductory Scientific Computing with Python Introductory Scientific Computing with Python More plotting, lists and FOSSEE Department of Aerospace Engineering IIT Bombay SciPy India, 2015 December, 2015 FOSSEE (FOSSEE IITB) Interactive Plotting 1

More information

short-reference.mht 1/ /WK/

short-reference.mht 1/ /WK/ short-reference.mht 1/6 6KRUW0$7/$%5HIHUHQFH There are many MATLAB features which cannot be included in these introductory notes. Listed below are some of the MATLAB functions and operators available,

More information

Built-in Types of Data

Built-in Types of Data Built-in Types of Data Types A data type is set of values and a set of operations defined on those values Python supports several built-in data types: int (for integers), float (for floating-point numbers),

More information

Effective Programming Practices for Economists. 10. Some scientific tools for Python

Effective Programming Practices for Economists. 10. Some scientific tools for Python Effective Programming Practices for Economists 10. Some scientific tools for Python Hans-Martin von Gaudecker Department of Economics, Universität Bonn A NumPy primer The main NumPy object is the homogeneous

More information

Introduction to Programming for Scientists

Introduction to Programming for Scientists Introduction to Programming for Scientists Lecture 7 Prof. Steven Ludtke N410, sludtke@bcm.edu 1 Homework Review import os, sys from PIL import Image import ImageFilter directory='g:/pictures' files=os.listdir(directory)

More information

Symbols. Anscombe s quartet, antiderivative, 200. bar charts for exercise, for expenses, Barnsley fern, drawing,

Symbols. Anscombe s quartet, antiderivative, 200. bar charts for exercise, for expenses, Barnsley fern, drawing, Index Symbols + (addition operator), 2 {} (curly brackets), to define a set, 122 δ (delta), 184 / (division operator), 2 ε (epsilon), 192, 197 199 == (equality operator), 124 e (Euler s number), 179 **

More information

ERTH3021 Exploration and Mining Geophysics

ERTH3021 Exploration and Mining Geophysics ERTH3021 Exploration and Mining Geophysics Practical 1: Introduction to Scientific Programming using Python Purposes To introduce simple programming skills using the popular Python language. To provide

More information

Chapter 1 MATLAB Preliminaries

Chapter 1 MATLAB Preliminaries Chapter 1 MATLAB Preliminaries 1.1 INTRODUCTION MATLAB (Matrix Laboratory) is a high-level technical computing environment developed by The Mathworks, Inc. for mathematical, scientific, and engineering

More information

Sunpy Python for Solar Physics Juan Carlos Martínez Oliveros

Sunpy Python for Solar Physics Juan Carlos Martínez Oliveros Sunpy Python for Solar Physics Juan Carlos Martínez Oliveros In the beginning (ENIAC) Evolution Evolution Evolution Introduction The SunPy project is an effort to create an opensource software library

More information

Episode 8 Matplotlib, SciPy, and Pandas. We will start with Matplotlib. The following code makes a sample plot.

Episode 8 Matplotlib, SciPy, and Pandas. We will start with Matplotlib. The following code makes a sample plot. Episode 8 Matplotlib, SciPy, and Pandas Now that we understand ndarrays, we can start using other packages that utilize them. In particular, we're going to look at Matplotlib, SciPy, and Pandas. Matplotlib

More information

Arithmetic and Logic Blocks

Arithmetic and Logic Blocks Arithmetic and Logic Blocks The Addition Block The block performs addition and subtractions on its inputs. This block can add or subtract scalar, vector, or matrix inputs. We can specify the operation

More information

NumPy. Daniël de Kok. May 4, 2017

NumPy. Daniël de Kok. May 4, 2017 NumPy Daniël de Kok May 4, 2017 Introduction Today Today s lecture is about the NumPy linear algebra library for Python. Today you will learn: How to create NumPy arrays, which store vectors, matrices,

More information

(DRAFT) PYTHON FUNDAMENTALS II: NUMPY & MATPLOTLIB

(DRAFT) PYTHON FUNDAMENTALS II: NUMPY & MATPLOTLIB (DRAFT) PYTHON FUNDAMENTALS II: NUMPY & MATPLOTLIB TROY P. KLING Contents 1. Importing Libraries 1 2. Introduction to numpy 2 3. Introduction to matplotlib 5 4. Image Processing 8 5. The Mandelbrot Set

More information

(5) ifit/math: «One Class to do some Math» God damn it! Just compute it! ifit workshop NBI Jan 2012 Math - 1

(5) ifit/math: «One Class to do some Math» God damn it! Just compute it! ifit workshop NBI Jan 2012 Math - 1 (5) ifit/math: «One Class to do some Math» God damn it! Just compute it! ifit workshop NBI Jan 2012 Math - 1 Math: perform mathematical operations seamlessly As we have seen there is a unique,

More information

Introduction to Matlab. Summer School CEA-EDF-INRIA 2011 of Numerical Analysis

Introduction to Matlab. Summer School CEA-EDF-INRIA 2011 of Numerical Analysis Introduction to Matlab 1 Outline What is Matlab? Matlab desktop & interface Scalar variables Vectors and matrices Exercise 1 Booleans Control structures File organization User defined functions Exercise

More information

Introduction to MATLAB. Simon O Keefe Non-Standard Computation Group

Introduction to MATLAB. Simon O Keefe Non-Standard Computation Group Introduction to MATLAB Simon O Keefe Non-Standard Computation Group sok@cs.york.ac.uk Content n An introduction to MATLAB n The MATLAB interfaces n Variables, vectors and matrices n Using operators n Using

More information

MATLAB QUICK START TUTORIAL

MATLAB QUICK START TUTORIAL MATLAB QUICK START TUTORIAL This tutorial is a brief introduction to MATLAB which is considered one of the most powerful languages of technical computing. In the following sections, the basic knowledge

More information

Homework 1 Description CmpE 362 Spring Instructor : Fatih Alagoz Teaching Assistant : Yekta Said Can Due: 3 March, 23:59, sharp

Homework 1 Description CmpE 362 Spring Instructor : Fatih Alagoz Teaching Assistant : Yekta Said Can Due: 3 March, 23:59, sharp Homework 1 Description CmpE 362 Spring 2016 Instructor : Fatih Alagoz Teaching Assistant : Yekta Said Can Due: 3 March, 23:59, sharp Homework 1 This homework is designed to teach you to think in terms

More information

Matlab Tutorial, CDS

Matlab Tutorial, CDS 29 September 2006 Arrays Built-in variables Outline Operations Linear algebra Polynomials Scripts and data management Help: command window Elisa (see Franco next slide), Matlab Tutorial, i.e. >> CDS110-101

More information

MS6021 Scientific Computing. TOPICS: Python BASICS, INTRO to PYTHON for Scientific Computing

MS6021 Scientific Computing. TOPICS: Python BASICS, INTRO to PYTHON for Scientific Computing MS6021 Scientific Computing TOPICS: Python BASICS, INTRO to PYTHON for Scientific Computing Preliminary Notes on Python (v MatLab + other languages) When you enter Spyder (available on installing Anaconda),

More information

2 Getting Started with Numerical Computations in Python

2 Getting Started with Numerical Computations in Python 1 Documentation and Resources * Download: o Requirements: Python, IPython, Numpy, Scipy, Matplotlib o Windows: google "windows download (Python,IPython,Numpy,Scipy,Matplotlib" o Debian based: sudo apt-get

More information

Programming for Engineers in Python

Programming for Engineers in Python Programming for Engineers in Python Autumn 2016-17 Lecture 11: NumPy & SciPy Introduction, Plotting and Data Analysis 1 Today s Plan Introduction to NumPy & SciPy Plotting Data Analysis 2 NumPy and SciPy

More information

Introduction to MATLAB Programming

Introduction to MATLAB Programming Introduction to MATLAB Programming Arun A. Balakrishnan Asst. Professor Dept. of AE&I, RSET Overview 1 Overview 2 Introduction 3 Getting Started 4 Basics of Programming Overview 1 Overview 2 Introduction

More information

A Guide to Using Some Basic MATLAB Functions

A Guide to Using Some Basic MATLAB Functions A Guide to Using Some Basic MATLAB Functions UNC Charlotte Robert W. Cox This document provides a brief overview of some of the essential MATLAB functionality. More thorough descriptions are available

More information

Python Advance Course via Astronomy street. Sérgio Sousa (CAUP) ExoEarths Team (http://www.astro.up.pt/exoearths/)

Python Advance Course via Astronomy street. Sérgio Sousa (CAUP) ExoEarths Team (http://www.astro.up.pt/exoearths/) Python Advance Course via Astronomy street Sérgio Sousa (CAUP) ExoEarths Team (http://www.astro.up.pt/exoearths/) Advance Course Outline: Python Advance Course via Astronomy street Lesson 1: Python basics

More information

Tutorial 2 PHY409 Anadi Canepa Office, TRIUMF MOB 92 B ( )

Tutorial 2 PHY409 Anadi Canepa Office, TRIUMF MOB 92 B ( ) Tutorial 2 PHY409 Anadi Canepa canepa@triumf.ca Office, TRIUMF MOB 92 B (1-604- 222-7330) Alan Manning mannin2@phas.ubc.ca Mohammad Samani samani@physics.ubc.ca During the 1 st tutorial We learnt What

More information

Introduction to MATLAB. Arturo Donate

Introduction to MATLAB. Arturo Donate Introduction to MATLAB Arturo Donate Introduction What is MATLAB? Environment MATLAB Basics Toolboxes Comparison Conclusion Programming What is MATLAB? Matrix laboratory programming environment high-performance

More information

Parakeet. A Runtime Compiler for Numerical Python

Parakeet. A Runtime Compiler for Numerical Python Parakeet A Runtime Compiler for Numerical Python Alex Rubinsteyn @ PyData Boston 2013 What s Parakeet? A runtime compiler for numerical Python Runtime Compiler When you call a function, Parakeet bakes

More information

1 2 (3 + x 3) x 2 = 1 3 (3 + x 1 2x 3 ) 1. 3 ( 1 x 2) (3 + x(0) 3 ) = 1 2 (3 + 0) = 3. 2 (3 + x(0) 1 2x (0) ( ) = 1 ( 1 x(0) 2 ) = 1 3 ) = 1 3

1 2 (3 + x 3) x 2 = 1 3 (3 + x 1 2x 3 ) 1. 3 ( 1 x 2) (3 + x(0) 3 ) = 1 2 (3 + 0) = 3. 2 (3 + x(0) 1 2x (0) ( ) = 1 ( 1 x(0) 2 ) = 1 3 ) = 1 3 6 Iterative Solvers Lab Objective: Many real-world problems of the form Ax = b have tens of thousands of parameters Solving such systems with Gaussian elimination or matrix factorizations could require

More information

Implement NN using NumPy

Implement NN using NumPy Implement NN using NumPy Hantao Zhang Deep Learning with Python Reading: https://www.tutorialspoint.com/numpy/ Recommendation for Using Python Install anaconda on your PC. If you already have installed

More information

Derek Bridge School of Computer Science and Information Technology University College Cork

Derek Bridge School of Computer Science and Information Technology University College Cork CS4618: rtificial Intelligence I Vectors and Matrices Derek Bridge School of Computer Science and Information Technology University College Cork Initialization In [1]: %load_ext autoreload %autoreload

More information

Bi 1x Spring 2014: Plotting and linear regression

Bi 1x Spring 2014: Plotting and linear regression Bi 1x Spring 2014: Plotting and linear regression In this tutorial, we will learn some basics of how to plot experimental data. We will also learn how to perform linear regressions to get parameter estimates.

More information

Introduction to Python Practical 1

Introduction to Python Practical 1 Introduction to Python Practical 1 Daniel Carrera & Brian Thorsbro October 2017 1 Introduction I believe that the best way to learn programming is hands on, and I tried to design this practical that way.

More information

Introduction to MATLAB Practical 1

Introduction to MATLAB Practical 1 Introduction to MATLAB Practical 1 Daniel Carrera November 2016 1 Introduction I believe that the best way to learn Matlab is hands on, and I tried to design this practical that way. I assume no prior

More information

Lezione 6. Installing NumPy. Contents

Lezione 6. Installing NumPy. Contents Lezione 6 Bioinformatica Mauro Ceccanti e Alberto Paoluzzi Dip. Informatica e Automazione Università Roma Tre Dip. Medicina Clinica Università La Sapienza Lab 01: Contents As with a lot of open-source

More information

Contents. Implementing the QR factorization The algebraic eigenvalue problem. Applied Linear Algebra in Geoscience Using MATLAB

Contents. Implementing the QR factorization The algebraic eigenvalue problem. Applied Linear Algebra in Geoscience Using MATLAB Applied Linear Algebra in Geoscience Using MATLAB Contents Getting Started Creating Arrays Mathematical Operations with Arrays Using Script Files and Managing Data Two-Dimensional Plots Programming in

More information

PC-MATLAB PRIMER. This is intended as a guided tour through PCMATLAB. Type as you go and watch what happens.

PC-MATLAB PRIMER. This is intended as a guided tour through PCMATLAB. Type as you go and watch what happens. PC-MATLAB PRIMER This is intended as a guided tour through PCMATLAB. Type as you go and watch what happens. >> 2*3 ans = 6 PCMATLAB uses several lines for the answer, but I ve edited this to save space.

More information

Practical Numpy and Matplotlib Intro

Practical Numpy and Matplotlib Intro Practical Numpy and Matplotlib Intro presented by Tom Adelman, Sept 28, 2012 What is Numpy? Advantages of using Numpy In [ ]: # an example n = 10000000 # Python a0 = [i for i in range(n)] time: 1.447 memory:

More information

MATLAB Premier. Middle East Technical University Department of Mechanical Engineering ME 304 1/50

MATLAB Premier. Middle East Technical University Department of Mechanical Engineering ME 304 1/50 MATLAB Premier Middle East Technical University Department of Mechanical Engineering ME 304 1/50 Outline Introduction Basic Features of MATLAB Prompt Level and Basic Arithmetic Operations Scalars, Vectors,

More information

Computer Science 121. Scientific Computing Winter 2016 Chapter 3 Simple Types: Numbers, Text, Booleans

Computer Science 121. Scientific Computing Winter 2016 Chapter 3 Simple Types: Numbers, Text, Booleans Computer Science 121 Scientific Computing Winter 2016 Chapter 3 Simple Types: Numbers, Text, Booleans 3.1 The Organization of Computer Memory Computers store information as bits : sequences of zeros and

More information

MATLAB Tutorial. Digital Signal Processing. Course Details. Topics. MATLAB Environment. Introduction. Digital Signal Processing (DSP)

MATLAB Tutorial. Digital Signal Processing. Course Details. Topics. MATLAB Environment. Introduction. Digital Signal Processing (DSP) Digital Signal Processing Prof. Nizamettin AYDIN naydin@yildiz.edu.tr naydin@ieee.org http://www.yildiz.edu.tr/~naydin Course Details Course Code : 0113620 Course Name: Digital Signal Processing (Sayısal

More information

Image Processing in Python

Image Processing in Python 1 Introduction Image Processing in Python During this exercise, the goal is to become familiar with Python and the NumPy library. You should also get a better feeling for how images are represented as

More information

MATLAB Basics EE107: COMMUNICATION SYSTEMS HUSSAIN ELKOTBY

MATLAB Basics EE107: COMMUNICATION SYSTEMS HUSSAIN ELKOTBY MATLAB Basics EE107: COMMUNICATION SYSTEMS HUSSAIN ELKOTBY What is MATLAB? MATLAB (MATrix LABoratory) developed by The Mathworks, Inc. (http://www.mathworks.com) Key Features: High-level language for numerical

More information

2.0 MATLAB Fundamentals

2.0 MATLAB Fundamentals 2.0 MATLAB Fundamentals 2.1 INTRODUCTION MATLAB is a computer program for computing scientific and engineering problems that can be expressed in mathematical form. The name MATLAB stands for MATrix LABoratory,

More information

PART 1 PROGRAMMING WITH MATHLAB

PART 1 PROGRAMMING WITH MATHLAB PART 1 PROGRAMMING WITH MATHLAB Presenter: Dr. Zalilah Sharer 2018 School of Chemical and Energy Engineering Universiti Teknologi Malaysia 23 September 2018 Programming with MATHLAB MATLAB Environment

More information

Python for Data Analysis. Prof.Sushila Aghav-Palwe Assistant Professor MIT

Python for Data Analysis. Prof.Sushila Aghav-Palwe Assistant Professor MIT Python for Data Analysis Prof.Sushila Aghav-Palwe Assistant Professor MIT Four steps to apply data analytics: 1. Define your Objective What are you trying to achieve? What could the result look like? 2.

More information

CDA5530: Performance Models of Computers and Networks. Chapter 8: Using Matlab for Performance Analysis and Simulation

CDA5530: Performance Models of Computers and Networks. Chapter 8: Using Matlab for Performance Analysis and Simulation CDA5530: Performance Models of Computers and Networks Chapter 8: Using Matlab for Performance Analysis and Simulation Objective Learn a useful tool for mathematical analysis and simulation Interpreted

More information

Lecturer: Keyvan Dehmamy

Lecturer: Keyvan Dehmamy MATLAB Tutorial Lecturer: Keyvan Dehmamy 1 Topics Introduction Running MATLAB and MATLAB Environment Getting help Variables Vectors, Matrices, and linear Algebra Mathematical Functions and Applications

More information

NumPy Primer. An introduction to numeric computing in Python

NumPy Primer. An introduction to numeric computing in Python NumPy Primer An introduction to numeric computing in Python What is NumPy? Numpy, SciPy and Matplotlib: MATLAB-like functionality for Python Numpy: Typed multi-dimensional arrays Fast numerical computation

More information

Variable Definition and Statement Suppression You can create your own variables, and assign them values using = >> a = a = 3.

Variable Definition and Statement Suppression You can create your own variables, and assign them values using = >> a = a = 3. MATLAB Introduction Accessing Matlab... Matlab Interface... The Basics... 2 Variable Definition and Statement Suppression... 2 Keyboard Shortcuts... More Common Functions... 4 Vectors and Matrices... 4

More information

MBI REU Matlab Tutorial

MBI REU Matlab Tutorial MBI REU Matlab Tutorial Lecturer: Reginald L. McGee II, Ph.D. June 8, 2017 MATLAB MATrix LABoratory MATLAB is a tool for numerical computation and visualization which allows Real & Complex Arithmetics

More information