Introduction to Scientific Computing with Python, part two.

Size: px
Start display at page:

Download "Introduction to Scientific Computing with Python, part two."

Transcription

1 Introduction to Scientific Computing with Python, part two. M. Emmett Department of Mathematics University of North Carolina at Chapel Hill June

2 The Zen of Python zen of python... fire up python and run: import this these slides are in the public domain

3 How I use Python Experimenting with complex algorithms: it s quick and relatively easy to try new things in Python vs C or Fortran 90. Debugging: interactively drawing things mid-algorithm is helpful for debugging. Analysis: loading and working with data, computing errors, drawing graphs, and making movies is relatively painless. Deployment: building and launching many jobs/experiments on KillDevil is very convenient (ie, control everything from your desktop).

4 Resources for scientific computing with Python NumPy and SciPy: Large collection of packages for: low-level numerical arrays (C/Fortran), sparse and dense linear algebra, FFTs, statistics etc... PyPI: The Python Package Index is a central place for authors to distribute Python packages Software Carpentry: Lectures/videos about scientific programming. Books by Prof. Langtangen: Prof. Langtangen has two great books on scientific computing with Python.

5 Python Packages Python has a batteries included philosophy. A standard Python installation contains many helpful packages. If the standard libraries don t have what you are looking for, there is a rich and growing collection of Python packages for many applications: system interaction, graphics, user interfaces, web programming, scientific computing, etc etc. Installing Python packages is relatively easy with pip:

6 ipython - Interactive Python Fire up ipython. It s an interactive Python prompt. I find it helpful for looking up documentation and experimenting with Python. A few helpful things: tab completion is your friend shell commands like cd and ls work?command shows help for a given command??command shows the source code for a given command run script.py runs the script script.py, and shows traces nicely

7 numpy - Numerical Python NumPy is the fundamental package for scientific computing with Python low-level (C/Fortran) N-dimensional arrays broadcasting, dot/matrix products linear algebra (LAPACK), FFTs etc Compare the following # using python lists and a for loop y = [] for k in range ( 10 ): x = k * 2* math. pi / 10 y. append ( math. sin (x)) # using numpy broadcasting x = np. arange (0.0, 2*np.pi, 2*np.pi/10) y = np.sin (x)

8 scipy - Scientific Python SciPy is a large collection of packages for more general scientific computing. ODE solvers and quadrature routines optimization and root finding signal processing sparse linear algebra statistics, distributions, random numbers masked arrays much more...

9 sympy - Symbolic Python SymPy is a package for performing symbolic calculations. import sympy x = sympy. var ( 'x ') p = x**2 + 5*x + 2 print p. diff (x) # 2* x + 5 SymPy also contains multi-precision math routines from sympy. mpmath import * print quad ( lambda x: 4* sqrt (1-x**2), [0, 1]) #

10 matplotlib - Plotting (similar in style to MATLAB) Matplotlib is a 2D plotting library that will be familiar to MATLAB users. import numpy as np import matplotlib. pylab as plt x = np. arange (0.0, 2*np.pi, 2*np.pi/20) y = np.sin (x) plt. plot (x, y, '-ok ') plt. show ()

11 fabric - Remote execution/deployment Fabric is a tool for executing commands on remote hosts. from fabric. api import def build (): with cd(env. work ): run ( 'make ') Then, on the command line I could run: $ fab -H killdevil build

12 h5py and pytables - HDF5 storage The HDF5 file format is a great way to store data and move it around (ie, platform independent storage). I like to think of it as a filesystem within a file. There are two Python packages that can read and write HDF5 files: h5py and pytables. For example import h5py output = h5py. File ( ' results.h5 ', 'w ') output. create_dataset ( ' pressure ', data = pressure ) output. create_dataset ( ' temperature ', data = temperature ) output. close () results = h5py. File ( ' results.h5 ', 'r ') pressure = results [ ' pressure '] temperatute = results [ ' temperature '] # do something with pressure, temperature results. close ()

13 mpi4py - Parallel computing (MPI) for Python There are many ways to do parallel computing. One of them is with a Message Passing Interface (MPI) library (of which there are several implementations). The mpi4py package provides a nice wrapper to the MPI routines: from mpi4py import MPI import numpy as np comm = MPI. COMM_ WORLD if comm. rank == 0: x = np. array ([1.0, 2.0, 3.0, 4.0]) else : x = np. zeros (4) comm. Bcast (x) print 'i am %d of %d ' % ( comm.rank, comm. size ), x

14 Other useful packages MMMMMOOORE! While creating this presentation I kept thinking of more cool packages that I have used... some of them include Mayavi - 3d graphics with OpenGL rendering Pandas - data analysis similar in style to R PyMC - Markov-Chain Monte-Carlo simulations many, many more...

15 Defining functions To define a function in Python, use the def keyword def f(x): """ Return cos (x) - x**3. This is an extended docstring. """ return np.cos (x) - x**3 Then, one can call the function by y = f(0.2) Note that documentation is, in some sense, part of the language.

16 Defining functions Default arguments def error (a, b, order = 'inf '): """ Compute the error between * a* and * b*. The * order * can be ' inf ' or 2. """ if order == 'inf ': return np.max ( abs (a-b)) elif order == 2: return np. sqrt (np.sum ((a-b )** 2)) raise ValueError ( ' invalid order ') Now you can call this as: err_def = error (a, b) err_inf = error (a, b, order = 'inf ') err_2 = error (a, b, order =2) err_ reorder = error ( b=x, a=y)

17 Defining functions Lambda forms Small throw-away functions can be created using the lambda keyword: square = lambda x: x** 2 print square ( 2) # 4 This is especially useful for functional programming x = [ 1, 2, 3, 4 ] y = map ( lambda x: x**2, x) print y # [ 1, 4, 9, 16 ]

18 List comprehensions Python has some nice language constructs to make programming look more mathematical. Consider the following statement Let Ω = { x 2 x N, x < 100, and x is prime } In Python, this is omega = [ x** 2 for x in range ( 100 ) if is_ prime ( x) ] A similar construct exists for creating dictionaries.

19 Map and reduce Functional programming The map routine applies a function to each element of a list. The following are equivalent y = [ math. sin ( x) for x in X ] y = map ( math.sin, X) The reduce routine applies a function in an aggregate manner to reduce lists. To compute the factorial of 10, one could f = reduce ( lambda x, y: x * y, range (1, 11 ))

20 NumPy: vector programming When working with NumPy arrays, one can # do scalar / vector multiplication a = 2.0 x = np. asarray ([1.0, 2.0, 3.0]) y = a * x # [ 2.0, 4.0, 6. 0 ] # do elementwise multiplication z = x * y # [ 2.0, 8.0, 18.0 ] # do matrix / vector multiplication A = np. asarray ([ [ 1.0, 2.0, 1.0 ], [ 2.0, -1.0, 1.0 ] ]) z = np.dot (A, x) Recall the broadcasting rules too (y = np.sin(x)).

21 Computing π There are many ways to numerically compute an approximate value of π. One way is to note that π 4 = arctan arctan 1 3 and use the Taylor expansion of arctan x about 0, which is arctan x x x x = k=0 ( 1) k x 1+2k 1 + 2k

22 Computing π Try it! Here is a start... x2, x3 = 1.0/2.0, 1.0/3.0 atan2, atan3 = 0.0, 0. 0 for k in range (5): atan2 +=... atan3 +=... print ' pi = ', 4. 0 * ( atan2 + atan3 ) Warning: Be careful when dividing integers in Python: sometimes 1/2 0.5 That s why I wrote 1.0/2.0 instead of 1/2. Challenge: can you use the sympy.mpmath module to go beyond 14 digits?

23 Spectral analysis Sometimes we want to know about the frequencies that exist in a signal. Consider the following signal (contain in y) import numpy as np x = np. arange (0.0, 2*np.pi, 2*np.pi/100 ) y = ( *np.sin (x) + 0.3*np.sin (5*x) + 0.1*np.sin (8*x) ) Can you plot the spectrum of this signal, with the zero frequency in the center?

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

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

Scientific Computing: Lecture 1

Scientific Computing: Lecture 1 Scientific Computing: Lecture 1 Introduction to course, syllabus, software Getting started Enthought Canopy, TextWrangler editor, python environment, ipython, unix shell Data structures in Python Integers,

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

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

NAVIGATING UNIX. Other useful commands, with more extensive documentation, are

NAVIGATING UNIX. Other useful commands, with more extensive documentation, are 1 NAVIGATING UNIX Most scientific computing is done on a Unix based system, whether a Linux distribution such as Ubuntu, or OSX on a Mac. The terminal is the application that you will use to talk to the

More information

Symbolic and Automatic Di erentiation in Python

Symbolic and Automatic Di erentiation in Python Lab 15 Symbolic and Automatic Di erentiation in Python Lab Objective: Python is good for more than just analysis of numerical data. There are several packages available which allow symbolic and automatic

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

MPI: the Message Passing Interface

MPI: the Message Passing Interface 15 Parallel Programming with MPI Lab Objective: In the world of parallel computing, MPI is the most widespread and standardized message passing library. As such, it is used in the majority of parallel

More information

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

Scientific Python. 1 of 10 23/11/ :00

Scientific Python.   1 of 10 23/11/ :00 Scientific Python Neelofer Banglawala Kevin Stratford nbanglaw@epcc.ed.ac.uk kevin@epcc.ed.ac.uk Original course authors: Andy Turner Arno Proeme 1 of 10 23/11/2015 00:00 www.archer.ac.uk support@archer.ac.uk

More information

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

Part VI. Scientific Computing in Python. Tobias Neckel: Scripting with Bash and Python Compact Max-Planck, February 16-26, Part VI Scientific Computing in Python Compact Course @ Max-Planck, February 16-26, 2015 81 More on Maths Module math Constants pi and e Functions that operate on int and float All return values float

More information

Numerical Integration

Numerical Integration Numerical Integration 1 Functions using Functions functions as arguments of other functions the one-line if-else statement functions returning multiple values 2 Constructing Integration Rules with sympy

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

Computational Programming with Python

Computational Programming with Python Numerical Analysis, Lund University, 2017 1 Computational Programming with Python Lecture 1: First steps - A bit of everything. Numerical Analysis, Lund University Lecturer: Claus Führer, Alexandros Sopasakis

More information

Scientific computing platforms at PGI / JCNS

Scientific computing platforms at PGI / JCNS Member of the Helmholtz Association Scientific computing platforms at PGI / JCNS PGI-1 / IAS-1 Scientific Visualization Workshop Josef Heinen Outline Introduction Python distributions The SciPy stack Julia

More information

Introduction to Machine Learning. Useful tools: Python, NumPy, scikit-learn

Introduction to Machine Learning. Useful tools: Python, NumPy, scikit-learn Introduction to Machine Learning Useful tools: Python, NumPy, scikit-learn Antonio Sutera and Jean-Michel Begon September 29, 2016 2 / 37 How to install Python? Download and use the Anaconda python distribution

More information

Cosmology with python: Beginner to Advanced in one week. Tiago Batalha de Castro

Cosmology with python: Beginner to Advanced in one week. Tiago Batalha de Castro Cosmology with python: Beginner to Advanced in one week Tiago Batalha de Castro What is Python? (From python.org) Python is an interpreted, object-oriented, high-level programming language with dynamic

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

HANDS ON DATA MINING. By Amit Somech. Workshop in Data-science, March 2016

HANDS ON DATA MINING. By Amit Somech. Workshop in Data-science, March 2016 HANDS ON DATA MINING By Amit Somech Workshop in Data-science, March 2016 AGENDA Before you start TextEditors Some Excel Recap Setting up Python environment PIP ipython Scientific computation in Python

More information

David J. Pine. Introduction to Python for Science & Engineering

David J. Pine. Introduction to Python for Science & Engineering David J. Pine Introduction to Python for Science & Engineering To Alex Pine who introduced me to Python Contents Preface About the Author xi xv 1 Introduction 1 1.1 Introduction to Python for Science and

More information

PYTHON NUMPY TUTORIAL CIS 581

PYTHON NUMPY TUTORIAL CIS 581 PYTHON NUMPY TUTORIAL CIS 581 VARIABLES AND SPYDER WORKSPACE Spyder is a Python IDE that s a part of the Anaconda distribution. Spyder has a Python console useful to run commands quickly and variables

More information

ARTIFICIAL INTELLIGENCE AND PYTHON

ARTIFICIAL INTELLIGENCE AND PYTHON ARTIFICIAL INTELLIGENCE AND PYTHON DAY 1 STANLEY LIANG, LASSONDE SCHOOL OF ENGINEERING, YORK UNIVERSITY WHAT IS PYTHON An interpreted high-level programming language for general-purpose programming. Python

More information

Numerical Methods. Centre for Mathematical Sciences Lund University. Spring 2015

Numerical Methods. Centre for Mathematical Sciences Lund University. Spring 2015 Numerical Methods Claus Führer Alexandros Sopasakis Centre for Mathematical Sciences Lund University Spring 2015 Preface These notes serve as a skeleton for the course. They document together with the

More information

Plotting With matplotlib

Plotting With matplotlib Lab Plotting With matplotlib and Mayavi Lab Objective: Introduce some of the basic plotting functions available in matplotlib and Mayavi. -D plotting with matplotlib The Python library matplotlib will

More information

Scientific Computing with Python. Quick Introduction

Scientific Computing with Python. Quick Introduction Scientific Computing with Python Quick Introduction Libraries and APIs A library is a collection of implementations of behavior (definitions) An Application Programming Interface (API) describes that behavior

More information

Python Programming. Hans-Petter Halvorsen.

Python Programming. Hans-Petter Halvorsen. Python Programming Hans-Petter Halvorsen https://www.halvorsen.blog Python Programming Python Programming Hans-Petter Halvorsen 2018 Python Programming c Hans-Petter Halvorsen December 20, 2018 1 Preface

More information

The Python interpreter

The Python interpreter The Python interpreter Daniel Winklehner, Remi Lehe US Particle Accelerator School (USPAS) Summer Session Self-Consistent Simulations of Beam and Plasma Systems S. M. Lund, J.-L. Vay, D. Bruhwiler, R.

More information

CME 193: Introduction to Scientific Python Lecture 1: Introduction

CME 193: Introduction to Scientific Python Lecture 1: Introduction CME 193: Introduction to Scientific Python Lecture 1: Introduction Nolan Skochdopole stanford.edu/class/cme193 1: Introduction 1-1 Contents Administration Introduction Basics Variables Control statements

More information

Introduction to Python

Introduction to Python Introduction to Python Ryan Gutenkunst Molecular and Cellular Biology University of Arizona Before we start, fire up your Amazon instance, open a terminal, and enter the command sudo apt-get install ipython

More information

Interactive Mode Python Pylab

Interactive Mode Python Pylab Short Python Intro Gerald Schuller, Nov. 2016 Python can be very similar to Matlab, very easy to learn if you already know Matlab, it is Open Source (unlike Matlab), it is easy to install, and unlike Matlab

More information

PYTHON FOR MEDICAL PHYSICISTS. Radiation Oncology Medical Physics Cancer Care Services, Royal Brisbane & Women s Hospital

PYTHON FOR MEDICAL PHYSICISTS. Radiation Oncology Medical Physics Cancer Care Services, Royal Brisbane & Women s Hospital PYTHON FOR MEDICAL PHYSICISTS Radiation Oncology Medical Physics Cancer Care Services, Royal Brisbane & Women s Hospital TUTORIAL 1: INTRODUCTION Thursday 1 st October, 2015 AGENDA 1. Reference list 2.

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

Research Computing with Python, Lecture 1

Research Computing with Python, Lecture 1 Research Computing with Python, Lecture 1 Ramses van Zon SciNet HPC Consortium November 4, 2014 Ramses van Zon (SciNet HPC Consortium)Research Computing with Python, Lecture 1 November 4, 2014 1 / 35 Introduction

More information

Arbitrary Precision and Symbolic Calculations

Arbitrary Precision and Symbolic Calculations Arbitrary Precision and Symbolic Calculations K. 1 1 Department of Mathematics 2018 Sympy There are several packages for Python that do symbolic mathematics. The most prominent of these seems to be Sympy.

More information

List Comprehensions and Simulations

List Comprehensions and Simulations List Comprehensions and Simulations 1 List Comprehensions examples in the Python shell zipping, filtering, and reducing 2 Monte Carlo Simulations testing the normal distribution the Mean Time Between Failures

More information

Scientific Computing with Python and CUDA

Scientific Computing with Python and CUDA Scientific Computing with Python and CUDA Stefan Reiterer High Performance Computing Seminar, January 17 2011 Stefan Reiterer () Scientific Computing with Python and CUDA HPC Seminar 1 / 55 Inhalt 1 A

More information

4. Modules and Functions

4. Modules and Functions 4. Modules and Functions The Usual Idea of a Function Topics Modules Using import Using functions from math A first look at defining functions sqrt 9 3 A factory that has inputs and builds outputs. Why

More information

Scientific Computing Using. Atriya Sen

Scientific Computing Using. Atriya Sen Scientific Computing Using Atriya Sen Broad Outline Part I, in which I discuss several aspects of the Python programming language Part II, in which I talk about some Python modules for scientific computing

More information

Computational Finance

Computational Finance Computational Finance Introduction to Matlab Marek Kolman Matlab program/programming language for technical computing particularly for numerical issues works on matrix/vector basis usually used for functional

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

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

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

Introduction to Python for Scientific Computing

Introduction to Python for Scientific Computing 1 Introduction to Python for Scientific Computing http://tinyurl.com/cq-intro-python-20151022 By: Bart Oldeman, Calcul Québec McGill HPC Bart.Oldeman@calculquebec.ca, Bart.Oldeman@mcgill.ca Partners and

More information

10.4 Linear interpolation method Newton s method

10.4 Linear interpolation method Newton s method 10.4 Linear interpolation method The next best thing one can do is the linear interpolation method, also known as the double false position method. This method works similarly to the bisection method by

More information

pandas: Rich Data Analysis Tools for Quant Finance

pandas: Rich Data Analysis Tools for Quant Finance pandas: Rich Data Analysis Tools for Quant Finance Wes McKinney April 24, 2012, QWAFAFEW Boston about me MIT 07 AQR Capital: 2007-2010 Global Macro and Credit Research WES MCKINNEY pandas: 2008 - Present

More information

Homework 11 - Debugging

Homework 11 - Debugging 1 of 7 5/28/2018, 1:21 PM Homework 11 - Debugging Instructions: Fix the errors in the following problems. Some of the problems are with the code syntax, causing an error message. Other errors are logical

More information

Chapter 2. Python Programming for Physicists. Soon-Hyung Yook. March 31, Soon-Hyung Yook Chapter 2 March 31, / 52

Chapter 2. Python Programming for Physicists. Soon-Hyung Yook. March 31, Soon-Hyung Yook Chapter 2 March 31, / 52 Chapter 2 Python Programming for Physicists Soon-Hyung Yook March 31, 2017 Soon-Hyung Yook Chapter 2 March 31, 2017 1 / 52 Table of Contents I 1 Getting Started 2 Basic Programming Variables and Assignments

More information

(Ca...

(Ca... 1 of 8 9/7/18, 1:59 PM Getting started with 228 computational exercises Many physics problems lend themselves to solution methods that are best implemented (or essentially can only be implemented) with

More information

Using the Matplotlib Library in Python 3

Using the Matplotlib Library in Python 3 Using the Matplotlib Library in Python 3 Matplotlib is a Python 2D plotting library that produces publication-quality figures in a variety of hardcopy formats and interactive environments across platforms.

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

Contents Computing with Formulas

Contents Computing with Formulas Contents 1 Computing with Formulas... 1 1.1 The First Programming Encounter: a Formula... 1 1.1.1 Using a Program as a Calculator... 2 1.1.2 About Programs and Programming... 2 1.1.3 Tools for Writing

More information

SECTION 1: INTRODUCTION. ENGR 112 Introduction to Engineering Computing

SECTION 1: INTRODUCTION. ENGR 112 Introduction to Engineering Computing SECTION 1: INTRODUCTION ENGR 112 Introduction to Engineering Computing 2 Course Overview What is Programming? 3 Programming The implementation of algorithms in a particular computer programming language

More information

Introduction to Python Part 2

Introduction to Python Part 2 Introduction to Python Part 2 v0.2 Brian Gregor Research Computing Services Information Services & Technology Tutorial Outline Part 2 Functions Tuples and dictionaries Modules numpy and matplotlib modules

More information

Pandas and Friends. Austin Godber Mail: Source:

Pandas and Friends. Austin Godber Mail: Source: Austin Godber Mail: godber@uberhip.com Twitter: @godber Source: http://github.com/desertpy/presentations What does it do? Pandas is a Python data analysis tool built on top of NumPy that provides a suite

More information

Getting along and working together. Fortran-Python Interoperability Jacob Wilkins

Getting along and working together. Fortran-Python Interoperability Jacob Wilkins Getting along and working together Fortran-Python Interoperability Jacob Wilkins Fortran AND Python working together? Fortran-Python May 2017 2/19 Two very different philosophies Two very different code-styles

More information

Intro to scientific Python in 45'

Intro to scientific Python in 45' Intro to scientific Python in 45' ... or Python for Matlab Users Getting help at the center Ask your questions on the martinos-python mailing list: martinos-python@nmr.mgh.harvard.edu you can at subscribe:

More information

An interesting related problem is Buffon s Needle which was first proposed in the mid-1700 s.

An interesting related problem is Buffon s Needle which was first proposed in the mid-1700 s. Using Monte Carlo to Estimate π using Buffon s Needle Problem An interesting related problem is Buffon s Needle which was first proposed in the mid-1700 s. Here s the problem (in a simplified form). Suppose

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

What advantages has it?

What advantages has it? by What advantages has it? The Reasons for Choosing Python Python is free It is object-oriented It is interpreted It is operating-system independent It has an excellent optimization module It offers modern

More information

AMath 483/583 Lecture 28 June 1, Notes: Notes: Python scripting for Fortran codes. Python scripting for Fortran codes.

AMath 483/583 Lecture 28 June 1, Notes: Notes: Python scripting for Fortran codes. Python scripting for Fortran codes. AMath 483/583 Lecture 28 June 1, 2011 Today: Python plus Fortran Comments on quadtests.py for project Linear vs. log-log plots Visualization Friday: Animation: plots to movies Binary I/O Parallel IPython

More information

Python for Data Analysis

Python for Data Analysis Python for Data Analysis Wes McKinney O'REILLY 8 Beijing Cambridge Farnham Kb'ln Sebastopol Tokyo Table of Contents Preface xi 1. Preliminaries " 1 What Is This Book About? 1 Why Python for Data Analysis?

More information

Matlab Tutorial. The value assigned to a variable can be checked by simply typing in the variable name:

Matlab Tutorial. The value assigned to a variable can be checked by simply typing in the variable name: 1 Matlab Tutorial 1- What is Matlab? Matlab is a powerful tool for almost any kind of mathematical application. It enables one to develop programs with a high degree of functionality. The user can write

More information

Data Science with Python Course Catalog

Data Science with Python Course Catalog Enhance Your Contribution to the Business, Earn Industry-recognized Accreditations, and Develop Skills that Help You Advance in Your Career March 2018 www.iotintercon.com Table of Contents Syllabus Overview

More information

Introduction to Engineering gii

Introduction to Engineering gii 25.108 Introduction to Engineering gii Dr. Jay Weitzen Lecture Notes I: Introduction to Matlab from Gilat Book MATLAB - Lecture # 1 Starting with MATLAB / Chapter 1 Topics Covered: 1. Introduction. 2.

More information

Doing a li6le astronomy with. Python. Ryan Cooke (K16) These slides & examples:

Doing a li6le astronomy with. Python. Ryan Cooke (K16) These slides & examples: Doing a li6le astronomy with Python Ryan Cooke (K16) These slides & examples: www.ast.cam.ac.uk/~rcooke/python/ An aside Let s begin by installing ATLAS: (AutomaIcally Tuned Linear Algebra SoKware) > cd

More information

Monte Carlo Integration

Monte Carlo Integration Lab 18 Monte Carlo Integration Lab Objective: Implement Monte Carlo integration to estimate integrals. Use Monte Carlo Integration to calculate the integral of the joint normal distribution. Some multivariable

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

LECTURE 0: Introduction and Background

LECTURE 0: Introduction and Background 1 LECTURE 0: Introduction and Background September 10, 2012 1 Computational science The role of computational science has become increasingly significant during the last few decades. It has become the

More information

Skills Quiz - Python Edition Solutions

Skills Quiz - Python Edition Solutions 'XNH8QLYHUVLW\ (GPXQG73UDWW-U6FKRRORI(QJLQHHULQJ EGR 103L Fall 2017 Skills Quiz - Python Edition Solutions Michael R. Gustafson II Name (please print): NetID (please print): In keeping with the Community

More information

Algorithms and Programming I. Lecture#12 Spring 2015

Algorithms and Programming I. Lecture#12 Spring 2015 Algorithms and Programming I Lecture#12 Spring 2015 Think Python How to Think Like a Computer Scientist By :Allen Downey Installing Python Follow the instructions on installing Python and IDLE on your

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

AUTHORS: FERNANDO PEREZ BRIAN E GRANGER (IEEE 2007) PRESENTED BY: RASHMISNATA ACHARYYA

AUTHORS: FERNANDO PEREZ BRIAN E GRANGER (IEEE 2007) PRESENTED BY: RASHMISNATA ACHARYYA I A system for Interactive Scientific Computing AUTHORS: FERNANDO PEREZ BRIAN E GRANGER (IEEE 2007) PRESENTED BY: RASHMISNATA ACHARYYA Key Idea and Background What is Ipython? Why Ipython? How, when and

More information

Introduction to MATLAB

Introduction to MATLAB Introduction to MATLAB Contents 1.1 Objectives... 1 1.2 Lab Requirement... 1 1.3 Background of MATLAB... 1 1.4 The MATLAB System... 1 1.5 Start of MATLAB... 3 1.6 Working Modes of MATLAB... 4 1.7 Basic

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

MO101: Python for Engineering Vladimir Paun ENSTA ParisTech

MO101: Python for Engineering Vladimir Paun ENSTA ParisTech I MO101: Python for Engineering Vladimir Paun ENSTA ParisTech License CC BY-NC-SA 2.0 http://creativecommons.org/licenses/by-nc-sa/2.0/fr/ Introduction to Python Introduction About Python Python itself

More information

Introduction to Python and NumPy I

Introduction to Python and NumPy I Introduction to Python and NumPy I This tutorial is continued in part two: Introduction to Python and NumPy II Table of contents Overview Launching Canopy Getting started in Python Getting help Python

More information

Python Scripting for Computational Science

Python Scripting for Computational Science Hans Petter Langtangen Python Scripting for Computational Science Third Edition With 62 Figures 43 Springer Table of Contents 1 Introduction... 1 1.1 Scripting versus Traditional Programming... 1 1.1.1

More information

A. Python Crash Course

A. Python Crash Course A. Python Crash Course Agenda A.1 Installing Python & Co A.2 Basics A.3 Data Types A.4 Conditions A.5 Loops A.6 Functions A.7 I/O A.8 OLS with Python 2 A.1 Installing Python & Co You can download and install

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

Certified Data Science with Python Professional VS-1442

Certified Data Science with Python Professional VS-1442 Certified Data Science with Python Professional VS-1442 Certified Data Science with Python Professional Certified Data Science with Python Professional Certification Code VS-1442 Data science has become

More information

debugging, hexadecimals, tuples

debugging, hexadecimals, tuples debugging, hexadecimals, tuples Matt Valeriote 28 January 2019 Searching for/asking for help Searching for help Google (or your search engine of choice) be as specific as possible Asking for help reproducible/minimal

More information

Computer Programming in MATLAB

Computer Programming in MATLAB Computer Programming in MATLAB Prof. Dr. İrfan KAYMAZ Atatürk University Engineering Faculty Department of Mechanical Engineering What is a computer??? Computer is a device that computes, especially a

More information

1. BASICS OF PYTHON. JHU Physics & Astronomy Python Workshop Lecturer: Mubdi Rahman

1. BASICS OF PYTHON. JHU Physics & Astronomy Python Workshop Lecturer: Mubdi Rahman 1. BASICS OF PYTHON JHU Physics & Astronomy Python Workshop 2017 Lecturer: Mubdi Rahman HOW IS THIS WORKSHOP GOING TO WORK? We will be going over all the basics you need to get started and get productive

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

Computational Physics

Computational Physics Computational Physics Python Programming Basics Prof. Paul Eugenio Department of Physics Florida State University Jan 17, 2019 http://hadron.physics.fsu.edu/~eugenio/comphy/ Announcements Exercise 0 due

More information

STAT/MATH 395 A - PROBABILITY II UW Winter Quarter Matlab Tutorial

STAT/MATH 395 A - PROBABILITY II UW Winter Quarter Matlab Tutorial STAT/MATH 395 A - PROBABILITY II UW Winter Quarter 2016 Néhémy Lim Matlab Tutorial 1 Introduction Matlab (standing for matrix laboratory) is a high-level programming language and interactive environment

More information

STATS 507 Data Analysis in Python. Lecture 2: Functions, Conditionals, Recursion and Iteration

STATS 507 Data Analysis in Python. Lecture 2: Functions, Conditionals, Recursion and Iteration STATS 507 Data Analysis in Python Lecture 2: Functions, Conditionals, Recursion and Iteration Functions in Python We ve already seen examples of functions: e.g., type()and print() Function calls take the

More information

Outline. CSE 1570 Interacting with MATLAB. Outline. Starting MATLAB. MATLAB Windows. MATLAB Desktop Window. Instructor: Aijun An.

Outline. CSE 1570 Interacting with MATLAB. Outline. Starting MATLAB. MATLAB Windows. MATLAB Desktop Window. Instructor: Aijun An. CSE 10 Interacting with MATLAB Instructor: Aijun An Department of Computer Science and Engineering York University aan@cse.yorku.ca Outline Starting MATLAB MATLAB Windows Using the Command Window Some

More information

This Worksheet shows you several ways to start using Enthought s distribution of Python!

This Worksheet shows you several ways to start using Enthought s distribution of Python! This Worksheet shows you several ways to start using Enthought s distribution of Python! Start the Terminal application by Selecting the Utilities item from the Go menu located at the top of the screen

More information

F21SC Industrial Programming: Python: Python Libraries

F21SC Industrial Programming: Python: Python Libraries F21SC Industrial Programming: Python: Python Libraries Hans-Wolfgang Loidl School of Mathematical and Computer Sciences, Heriot-Watt University, Edinburgh Semester 1 2017/18 0 No proprietary software has

More information

Intelligente Datenanalyse Intelligent Data Analysis

Intelligente Datenanalyse Intelligent Data Analysis Universität Potsdam Institut für Informatik Lehrstuhl Maschinelles Lernen Intelligent Data Analysis Tobias Scheffer, Gerrit Gruben, Nuno Marquez Plan for this lecture Introduction to Python Main goal is

More information

Appendix A. Introduction to MATLAB. A.1 What Is MATLAB?

Appendix A. Introduction to MATLAB. A.1 What Is MATLAB? Appendix A Introduction to MATLAB A.1 What Is MATLAB? MATLAB is a technical computing environment developed by The Math- Works, Inc. for computation and data visualization. It is both an interactive system

More information

AMS 27L LAB #1 Winter 2009

AMS 27L LAB #1 Winter 2009 AMS 27L LAB #1 Winter 2009 Introduction to MATLAB Objectives: 1. To introduce the use of the MATLAB software package 2. To learn elementary mathematics in MATLAB Getting Started: Log onto your machine

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

: Intro Programming for Scientists and Engineers Final Exam

: Intro Programming for Scientists and Engineers Final Exam Final Exam Page 1 of 6 600.112: Intro Programming for Scientists and Engineers Final Exam Peter H. Fröhlich phf@cs.jhu.edu December 20, 2012 Time: 40 Minutes Start here: Please fill in the following important

More information

Python Scripting for Computational Science

Python Scripting for Computational Science Hans Petter Langtangen Python Scripting for Computational Science Third Edition With 62 Figures Sprin ger Table of Contents 1 Introduction 1 1.1 Scripting versus Traditional Programming 1 1.1.1 Why Scripting

More information

Introduction to Python Part 1. Brian Gregor Research Computing Services Information Services & Technology

Introduction to Python Part 1. Brian Gregor Research Computing Services Information Services & Technology Introduction to Python Part 1 Brian Gregor Research Computing Services Information Services & Technology RCS Team and Expertise Our Team Scientific Programmers Systems Administrators Graphics/Visualization

More information

Introduction to Scientific Python, CME 193 Jan. 9, web.stanford.edu/~ermartin/teaching/cme193-winter15

Introduction to Scientific Python, CME 193 Jan. 9, web.stanford.edu/~ermartin/teaching/cme193-winter15 1 LECTURE 1: INTRO Introduction to Scientific Python, CME 193 Jan. 9, 2014 web.stanford.edu/~ermartin/teaching/cme193-winter15 Eileen Martin Some slides are from Sven Schmit s Fall 14 slides 2 Course Details

More information

Getting Started. Office Hours. CSE 231, Rich Enbody. After class By appointment send an . Michigan State University CSE 231, Fall 2013

Getting Started. Office Hours. CSE 231, Rich Enbody. After class By appointment send an  . Michigan State University CSE 231, Fall 2013 CSE 231, Rich Enbody Office Hours After class By appointment send an email 2 1 Project 1 Python arithmetic Do with pencil, paper and calculator first Idle Handin Help room 3 What is a Computer Program?

More information