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

Size: px
Start display at page:

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

Transcription

1 Effective Programming Practices for Economists 10. Some scientific tools for Python Hans-Martin von Gaudecker Department of Economics, Universität Bonn

2 A NumPy primer The main NumPy object is the homogeneous multidimensional array Array: Table of elements, indexed by a tuple of integers Homogenous: Elements are of the same type Multidimensional: Can have several dimensions (called axes in NumPy-speak, since dimensions is ambiguous. Number of axes is often called rank ) For creating an ndarray object, you can use numpy.array Be sure to do the import correctly, Python s standard library also provides an array object... Licensed under the Creative Commons Attribution License 2/27

3 Basic usage of ndarray objects Create an array using numpy.array... >>> import numpy as np >>> a = np.array([[1.0, 2.2], [-1, 3.0]]) >>> a array([[ 1., 2.2], [-1., 3. ]]) Sequence: 1d, sequence of sequences: 2d, seq. of seq. s of seq. s: 3d, and so on Be careful to use a sequence and not np.array(1, 2, 3, 4) or np.array([1, 2], [3, 4]))... or fancier constructs: >>> b = np.arange(10).reshape(2, 5) >>> b array([[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]]) Licensed under the Creative Commons Attribution License 3/27

4 Basic usage of ndarray objects See basic properties via attributes shape, ndim, size, and dtype: >>> for i in a, b:... print(i.shape)... print(i.ndim)... print(i.size)... print(i.dtype) (2, 2) 2 4 float64 (2, 5) 2 10 int64 Licensed under the Creative Commons Attribution License 4/27

5 Basic usage of ndarray objects Convenience functions for array creation: zeros([shape]), ones([shape]), diag([sequence on diagonal]): >>> c = np.zeros([1, 2, 3]) >>> c.ndim >>> c 3 array([[[ 0., 0., 0.], [ 0., 0., 0.]]]) >>> d = np.diag([1] * 3) >>> d.ndim >>> d 2 array([[1, 0, 0], [0, 1, 0], [0, 0, 1]]) Licensed under the Creative Commons Attribution License 5/27

6 Basic usage of ndarray objects And one more convenience function: linspace(lower, upper, n_grid_points): >>> np.linspace(-.5,.5, 9) array([-0.5, , -0.25, , 0., 0.125, 0.25, 0.375, 0.5 ]) Useful to evaluate or plot functions on a grid... Licensed under the Creative Commons Attribution License 6/27

7 Basic operations with ndarray objects All basic operations apply element-wise >>> a = np.array([20,30,40,50]) >>> b = np.arange(4) >>> c = a - b >>> c array([20, 29, 38, 47]) >>> b ** 2 array([0, 1, 4, 9]) >>> 10 * sin(a) array([ , , , ]) >>> a < 35 array([true, True, False, False], dtype=bool) Licensed under the Creative Commons Attribution License 7/27

8 Basic operations with ndarray objects The operator performs element-by-element multiplication >>> A = np.array([[1, 1],... [0, 1]]) >>> B = np.array([[2, 0],... [3, 4]]) >>> A * B array([[2, 0], [0, 4]]) Use NumPy s dot() function for the matrix product... >>> np.dot(a, B) array([[5, 4], [3, 4]]) Licensed under the Creative Commons Attribution License 8/27

9 Indexing, slicing and iterating One dimensional arrays can be indexed, sliced and iterated over like lists and other Python sequences Multidimensional arrays can be indexed / sliced with one index per axis. These indices are given in a tuple separated by commas: >>> B[1, 1] 4 >>> B[0, :] array([2, 0]) >>> B[0] array([2, 0]) Licensed under the Creative Commons Attribution License 9/27

10 Indexing, slicing and iterating Slices also return views (references to the slice of the original array in memory) >>> c = B[0, :] >>> c[:] = [1, 1] >>> B array([[1, 1], [3, 4]]) Use the copy() method of an ndarray to get a copy >>> d = B[0, :].copy() >>> d[:] = [3, 3] >>> B array([[1, 1], [3, 4]]) Licensed under the Creative Commons Attribution License 10/27

11 Some useful references Tutorial (very clear examples): User guide (getting more complete): Reference (detailed explanations, but no easy read): Nice, slightly technical exposition: Walt, Colbert, and Varoquaux (2011) If you re used to Matlab... numpy-for-matlab-users.html... continued, but also R included: Licensed under the Creative Commons Attribution License 11/27

12 Matplotlib Publication-quality 2-dimensional plots >>> import matplotlib.pyplot as plt >>> plt.plot([-500, 0, 550], [-1000, 0, 550]) >>> plt.show() Licensed under the Creative Commons Attribution License 12/27

13 Change the axes, add title >>> plt.axis((-600.0, 600.0, , )) (-600.0, 600.0, , ) >>> plt.title('piecewise-linear utility function') <matplotlib.text.text object at 0x1027c3110> >>> plt.xlabel('gamble outcome') <matplotlib.text.text object at 0x1027b7cd0> >>> plt.ylabel('utility evaluation') <matplotlib.text.text object at 0x1027b9c50> Licensed under the Creative Commons Attribution License 13/27

14 Saving the figure >>> plt.savefig('linear_utility_3.png') 1000 Piecewise-linear utility function 500 Utility evaluation Gamble outcome Licensed under the Creative Commons Attribution License 14/27

15 Example: Comparing utility functions import os import numpy as np from matplotlib import pyplot from src.examples.scientific_tools.utility_functions import ce # Set the number of gridpoints for evaluation of the certainty equivalents. N_GRIDPOINTS = 101 # Define the outcomes of the lottery. z_low = z_high = # Define the parameters of the utility function. preference_specifications = [{'func': 'pow', 'gamma': 0.3, 'lambda': 2.0}] preference_specifications.append({'func': 'exp', 'gamma': 0.001, 'lambda': 2.0}) # Labels for the utility functions to be used in output. preference_label = {'exp': 'Exponential', 'pow': 'Power'} legend = [] # Define grids for probabilities and certainty equivalent evaluations. p_grid = np.linspace(0, 1, N_GRIDPOINTS) ce_grid = np.empty((len(preference_specifications), N_GRIDPOINTS)) Licensed under the Creative Commons Attribution License 15/27

16 # Define the basic characteristics of the figure. pyplot.plot() pyplot.title('certainty equivalent of [{}, {}]'.format(z_low, z_high)) pyplot.xlabel('probability of {} to occur'.format(z_high)) pyplot.ylabel('certainty equivalent') pyplot.axis([0, 1, -750, 600]) pyplot.grid(true) # Calculate and plot the utility values. for i, preference_specification in enumerate(preference_specifications): for j, p_high in enumerate(p_grid): lottery = {z_low: p_high, z_high: p_high} ce_grid[i, j] = ce(lottery, preference_specification) # Add plot to the figure, define legend. pyplot.plot(p_grid, ce_grid[i]) legend.append(r'{utl} utility, $\gamma$={gam}, $\lambda$={lam}'.format( utl=preference_label[preference_specification['func']], gam=preference_specification['gamma'], lam=preference_specification['lambda'] )) pyplot.legend(legend, loc='lower center') pyplot.savefig(os.path.join(out_path, 'utility_exponential_vs_power.pdf')) Licensed under the Creative Commons Attribution License 16/27

17 Example: Comparing utility functions 600 Certainty equivalent of [-500.0, 550.0] 400 Certainty equivalent Power utility, γ=0.3, λ=2.0 Exponential utility, γ=0.001, λ= Probability of to occur Licensed under the Creative Commons Attribution License 17/27

18 What else you can do with Matplotlib... Licensed under the Creative Commons Attribution License 18/27

19 What else you can do with Matplotlib... All the examples from the previous slide and many more you find along with the relevant source code at: Great way to get started Another good reference read is Tosi (2009) Licensed under the Creative Commons Attribution License 19/27

20 A very quick introduction to SciPy SciPy contains all kinds of useful tools for scientific applications Builds on top of NumPy, many things require to be passed ndarrays Often routines are just interfaces to classic (and fast) C or Fortran libraries Licensed under the Creative Commons Attribution License 20/27

21 A very quick introduction to SciPy Build in modular form import scipy not very useful Rather use statements like: from scipy.optimize import minimize Most relevant components to typical economics application: scipy.integrate scipy.optimize scipy.stats scipy.linalg Licensed under the Creative Commons Attribution License 21/27

22 Typical usage of scipy.optimize >>> from scipy.optimize import minimize >>> def g(x):... return x ** 2... >>> minimize(g, 200) success: True status: 0 jac: array([ e-11]) nfev: 15 njev: 5 hess: array([[ ]]) message: 'Optimization terminated successfully.' x: array([ e-09]) fun: e-17 Licensed under the Creative Commons Attribution License 22/27

23 Typical usage of scipy.optimize scipy.minimize provides a unified interface to many optimizers Full syntax of underlying functions is often scary... fmin_bfgs( f, x0, fprime, args, gtol, norm, epsilon, maxiter, full_output, disp, retall, callback )... but very seldomly needed Look through it if you use things seriously Licensed under the Creative Commons Attribution License 23/27

24 Further extensions... pandas very useful data structures + descriptives: StatsModels statistics & econometrics OLS, ML, time series, much more stuff Seaborn statistical visualisation on top of MPL: So called scikits provide specialised extensions to SciPy, see Index of extra tools loosely related to SciPy (careful not everything continues to be maintained): Licensed under the Creative Commons Attribution License 24/27

25 References I Tosi, Sandro (2009). Matplotlib for Python Developers. Birmingham, UK: Packt Publishing. Walt, Stéfan van der, S. Chris Colbert, and Gaël Varoquaux (2011). The NumPy Array: A Structure for Efficient Numerical Computation. In: Computing in Science & Engineering 13.2, pp Licensed under the Creative Commons Attribution License 25/27

26 Acknowledgements This course is designed after and borrows a lot from the Software Carpentry course designed by Greg Wilson for scientists and engineers. The Software Carpentry course material is made available under a Creative Commons Attribution License, as is this course s material. Licensed under the Creative Commons Attribution License 26/27

27 License for the course material [Links to the full legal text and the source text for this page.] You are free: to Share to copy, distribute and transmit the work to Remix to adapt the work Under the following conditions: Attribution You must attribute the work in the manner specified by the author or licensor (but not in any way that suggests that they endorse you or your use of the work). With the understanding that: Waiver Any of the above conditions can be waived if you get permission from the copyright holder. Public Domain Where the work or any of its elements is in the public domain under applicable law, that status is in no way affected by the license. Other Rights In no way are any of the following rights affected by the license: Your fair dealing or fair use rights, or other applicable copyright exceptions and limitations; The author s moral rights; Rights other persons may have either in the work itself or in how the work is used, such as publicity or privacy rights. Notice For any reuse or distribution, you must make clear to others the license terms of this work. The best way to do this is with a link to this web page.

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

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

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

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

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

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

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

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

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

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

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

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

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

Effective Programming Practices for Economists

Effective Programming Practices for Economists Effective Programming Practices for Economists 14. Object-oriented programming Hans-Martin von Gaudecker Department of Economics, Universität Bonn Revisiting abstractions Reminder of the example Reconsider

More information

MATPLOTLIB. Python for computational science November 2012 CINECA.

MATPLOTLIB. Python for computational science November 2012 CINECA. MATPLOTLIB Python for computational science 19 21 November 2012 CINECA m.cestari@cineca.it Introduction (1) plotting the data gives us visual feedback in the working process Typical workflow: write a python

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

(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

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

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

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

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

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

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

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

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

INTRODUCTION TO DATA SCIENCE

INTRODUCTION TO DATA SCIENCE INTRODUCTION TO DATA SCIENCE JOHN P DICKERSON PREM SAGGAR Today! Lecture #3 9/5/2018 CMSC320 Mondays & Wednesdays 2pm 3:15pm ANNOUNCEMENTS Register on Piazza: piazza.com/umd/fall2018/cmsc320 219 have registered

More information

Effective Programming Practices for Economists. 17. Regular Expressions

Effective Programming Practices for Economists. 17. Regular Expressions Effective Programming Practices for Economists 17. Regular Expressions Hans-Martin von Gaudecker Department of Economics, Universität Bonn Motivation Replace all occurences of my name in the project template

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

Effective Programming Practices for Economists

Effective Programming Practices for Economists Effective Programming Practices for Economists 4. A L A T E X primer Hans-Martin von Gaudecker Department of Economics, Universität Bonn The case for plain L A T E X Version control works best with simple

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

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

Chapter 5 : Informatics Practices. Class XII ( As per CBSE Board) Numpy - Array. New Syllabus Visit : python.mykvs.in for regular updates

Chapter 5 : Informatics Practices. Class XII ( As per CBSE Board) Numpy - Array. New Syllabus Visit : python.mykvs.in for regular updates Chapter 5 : Informatics Practices Class XII ( As per CBSE Board) Numpy - Array New Syllabus 2019-20 NumPy stands for Numerical Python.It is the core library for scientific computing in Python. It consist

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

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

Handling arrays in Python (numpy)

Handling arrays in Python (numpy) Handling arrays in Python (numpy) Thanks to all contributors: Alison Pamment, Sam Pepler, Ag Stephens, Stephen Pascoe, Anabelle Guillory, Graham Parton, Esther Conway, Wendy Garland, Alan Iwi and Matt

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

INTRODUCTION TO DATA SCIENCE

INTRODUCTION TO DATA SCIENCE INTRODUCTION TO DATA SCIENCE JOHN P DICKERSON Lecture #3 2/2/2017 CMSC320 Tuesdays & Thursdays 3:30pm 4:45pm ANNOUNCEMENTS Register on Piazza: piazza.com/umd/spring2017/cmsc320 74 have registered already

More information

Session 04: Introduction to Numpy

Session 04: Introduction to Numpy Session 04: Introduction to Numpy October 9th, 2017 Wouter Klijn Overview Introduction Hello world Arrays Creating Interacting Copying Differences with Matlab Matrixes vs Array Why Why not Matlib module

More information

Effective Programming Practices for Economists. 13. Documenting (the code of) research projects

Effective Programming Practices for Economists. 13. Documenting (the code of) research projects Effective Programming Practices for Economists 13. Documenting (the code of) research projects Hans-Martin von Gaudecker Department of Economics, Universität Bonn At the end of this lecture you are able

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 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

Effective Programming Practices for Economists. 7. Version Control, Part II: Git with a Shared Repository

Effective Programming Practices for Economists. 7. Version Control, Part II: Git with a Shared Repository Effective Programming Practices for Economists 7. Version Control, Part II: Git with a Shared Repository Hans-Martin von Gaudecker Department of Economics, Universität Bonn Collaboration Science in general

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

Python in Economics and Finance

Python in Economics and Finance Python in Economics and Finance Part 2 John Stachurski, ANU June 2014 Topics Data types OOP Iteration Functions NumPy / SciPy Matplotlib Data Types We have already met several native Python data types»>

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

Week Two. Arrays, packages, and writing programs

Week Two. Arrays, packages, and writing programs Week Two Arrays, packages, and writing programs Review UNIX is the OS/environment in which we work We store files in directories, and we can use commands in the terminal to navigate around, make and delete

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

Intermediate/Advanced Python. Michael Weinstein (Day 2)

Intermediate/Advanced Python. Michael Weinstein (Day 2) Intermediate/Advanced Python Michael Weinstein (Day 2) Topics Review of basic data structures Accessing and working with objects in python Numpy How python actually stores data in memory Why numpy can

More information

Ch.1 Introduction. Why Machine Learning (ML)? manual designing of rules requires knowing how humans do it.

Ch.1 Introduction. Why Machine Learning (ML)? manual designing of rules requires knowing how humans do it. Ch.1 Introduction Syllabus, prerequisites Notation: Means pencil-and-paper QUIZ Means coding QUIZ Code respository for our text: https://github.com/amueller/introduction_to_ml_with_python Why Machine Learning

More information

NumPy. Arno Proeme, ARCHER CSE Team Attributed to Jussi Enkovaara & Martti Louhivuori, CSC Helsinki

NumPy. Arno Proeme, ARCHER CSE Team Attributed to Jussi Enkovaara & Martti Louhivuori, CSC Helsinki NumPy Arno Proeme, ARCHER CSE Team aproeme@epcc.ed.ac.uk Attributed to Jussi Enkovaara & Martti Louhivuori, CSC Helsinki Reusing this material This work is licensed under a Creative Commons Attribution-

More information

Lecture 15: High Dimensional Data Analysis, Numpy Overview

Lecture 15: High Dimensional Data Analysis, Numpy Overview Lecture 15: High Dimensional Data Analysis, Numpy Overview Chris Tralie, Duke University 3/3/2016 Announcements Mini Assignment 3 Out Tomorrow, due next Friday 3/11 11:55PM Rank Top 3 Final Project Choices

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

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

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

Advanced Python on Abel. Dmytro Karpenko Research Infrastructure Services group Department for Scientific Computing USIT, UiO

Advanced Python on Abel. Dmytro Karpenko Research Infrastructure Services group Department for Scientific Computing USIT, UiO Advanced Python on Abel Dmytro Karpenko Research Infrastructure Services group Department for Scientific Computing USIT, UiO Support for large, multi-dimensional arrays and matrices, and a large library

More information

NumPy. Computational Physics. NumPy

NumPy. Computational Physics. NumPy NumPy Computational Physics NumPy Outline Some Leftovers Get people on line! Write a function / Write a script NumPy NumPy Arrays; dexing; Iterating Creating Arrays Basic Operations Copying Linear Algebra

More information

numpy-scipy February 11, 2015

numpy-scipy February 11, 2015 numpy-scipy February 11, 2015 Contents 0.1 Introduction to Scientific Programming with Python....................... 1 0.1.1 Session 4: NumPy, SciPy & matplotlib........................... 1 0.1.2 Outline:............................................

More information

MLCV 182: Practical session 1 Ron Shapira Weber Computer Science, Ben-Gurion University

MLCV 182: Practical session 1 Ron Shapira Weber Computer Science, Ben-Gurion University MLCV 182: Practical session 1 Ron Shapira Weber Computer Science, Ben-Gurion University Getting Started There are two different versions of Python being supported at the moment, 2.7 and 3.6. For compatibility

More information

Introduction to Artificial Neural Networks and Deep Learning

Introduction to Artificial Neural Networks and Deep Learning Introduction to Artificial Neural Networks and Deep Learning A Practical Guide with Applications in Python Sebastian Raschka This book is for sale at http://leanpub.com/ann-and-deeplearning This version

More information

Python (version 3.6) for R Users: Stat Modules I

Python (version 3.6) for R Users: Stat Modules I Python (version 3.6) for R Users: Stat Modules I CMU MSP 36601, Fall 2017, Howard Seltman 1. Use the numpy module to get vector, matrix, and array functionality as well as linear algebra. The official

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

INTRODUCTION TO DATA VISUALIZATION WITH PYTHON. Working with 2D arrays

INTRODUCTION TO DATA VISUALIZATION WITH PYTHON. Working with 2D arrays INTRODUCTION TO DATA VISUALIZATION WITH PYTHON Working with 2D arrays Reminder: NumPy arrays Homogeneous in type Calculations all at once Indexing with brackets: A[index] for 1D array A[index0, index1]

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

The NumPy Array: A Structure for Efficient Numerical Computation

The NumPy Array: A Structure for Efficient Numerical Computation The NumPy Array: A Structure for Efficient Numerical Computation Presented at the G-Node Autumn School on Advanced Scientific Programming in Python, held in Kiel, Germany Stéfan van der Walt UC Berkeley

More information

Python Numpy (1) Intro to multi-dimensional array & numerical linear algebra. Harry Lee January 29, 2018 CEE 696

Python Numpy (1) Intro to multi-dimensional array & numerical linear algebra. Harry Lee January 29, 2018 CEE 696 Python Numpy (1) Intro to multi-dimensional array & numerical linear algebra Harry Lee January 29, 2018 CEE 696 Table of contents 1. Introduction 2. Linear Algebra 1 Introduction From the last lecture

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

Matplotlib Python Plotting

Matplotlib Python Plotting Matplotlib Python Plotting 1 / 6 2 / 6 3 / 6 Matplotlib Python Plotting Matplotlib is a Python 2D plotting library which produces publication quality figures in a variety of hardcopy formats and interactive

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

COMP1730/COMP6730 Programming for Scientists. Sequence types, part 2

COMP1730/COMP6730 Programming for Scientists. Sequence types, part 2 COMP1730/COMP6730 Programming for Scientists Sequence types, part 2 Lecture outline * Lists * Mutable objects & references Sequence data types (recap) * A sequence contains n 0 values (its length), each

More information

cosmos_python_ Python as calculator May 31, 2018

cosmos_python_ Python as calculator May 31, 2018 cosmos_python_2018 May 31, 2018 1 Python as calculator Note: To convert ipynb to pdf file, use command: ipython nbconvert cosmos_python_2015.ipynb --to latex --post pdf In [3]: 1 + 3 Out[3]: 4 In [4]:

More information

Introduction to Python: The Multi-Purpose Programming Language. Robert M. Porsch June 14, 2017

Introduction to Python: The Multi-Purpose Programming Language. Robert M. Porsch June 14, 2017 Introduction to Python: The Multi-Purpose Programming Language Robert M. Porsch June 14, 2017 What is Python Python is Python is a widely used high-level programming language for general-purpose programming

More information

Lab 1 - Basic ipython Tutorial (EE 126 Fall 2014)

Lab 1 - Basic ipython Tutorial (EE 126 Fall 2014) Lab 1 - Basic ipython Tutorial (EE 126 Fall 2014) modified from Berkeley Python Bootcamp 2013 https://github.com/profjsb/python-bootcamp and Python for Signal Processing http://link.springer.com/book/10.1007%2f978-3-319-01342-8

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

An introduction to Python. Matteo Degiacomi December 2017

An introduction to Python. Matteo Degiacomi December 2017 An introduction to Python Matteo Degiacomi December 2017 TIOBE Programming Community index: Python ranked 4 th most popular language What makes a good programming language? Readable Concise Large ecosystem

More information

The NumPy array: a structure for efficient numerical computation

The NumPy array: a structure for efficient numerical computation The NumPy array: a structure for efficient numerical computation Stefan Van Der Walt, S. Chris Colbert, Gaël Varoquaux To cite this version: Stefan Van Der Walt, S. Chris Colbert, Gaël Varoquaux. The NumPy

More information

Interpolation and curve fitting

Interpolation and curve fitting CITS2401 Computer Analysis and Visualization School of Computer Science and Software Engineering Lecture 9 Interpolation and curve fitting 1 Summary Interpolation Curve fitting Linear regression (for single

More information

HW0 v3. October 2, CSE 252A Computer Vision I Fall Assignment 0

HW0 v3. October 2, CSE 252A Computer Vision I Fall Assignment 0 HW0 v3 October 2, 2018 1 CSE 252A Computer Vision I Fall 2018 - Assignment 0 1.0.1 Instructor: David Kriegman 1.0.2 Assignment Published On: Tuesday, October 2, 2018 1.0.3 Due On: Tuesday, October 9, 2018

More information

Paraphrase Identification; Numpy; Scikit-Learn

Paraphrase Identification; Numpy; Scikit-Learn Paraphrase Identification; Numpy; Scikit-Learn Benjamin Roth Centrum für Informations- und Sprachverarbeitung Ludwig-Maximilian-Universität München beroth@cis.uni-muenchen.de Benjamin Roth (CIS) Paraphrase

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

Numpy fast array interface

Numpy fast array interface NUMPY Numpy fast array interface Standard Python is not well suitable for numerical computations lists are very flexible but also slow to process in numerical computations Numpy adds a new array data type

More information

5 File I/O, Plotting with Matplotlib

5 File I/O, Plotting with Matplotlib 5 File I/O, Plotting with Matplotlib Bálint Aradi Course: Scientific Programming / Wissenchaftliches Programmieren (Python) Installing some SciPy stack components We will need several Scipy components

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

Short Introduction to Python Machine Learning Course Laboratory

Short Introduction to Python Machine Learning Course Laboratory Pattern Recognition and Applications Lab Short Introduction to Python Machine Learning Course Laboratory Battista Biggio battista.biggio@diee.unica.it Luca Didaci didaci@diee.unica.it Dept. Of Electrical

More information

Introducing Python Pandas

Introducing Python Pandas Introducing Python Pandas Based on CBSE Curriculum Class -11 By- Neha Tyagi PGT CS KV 5 Jaipur II Shift Jaipur Region Neha Tyagi, KV 5 Jaipur II Shift Introduction Pandas or Python Pandas is a library

More information

Python VSIP API: A first draft

Python VSIP API: A first draft Python VSIP API: A first draft Stefan Seefeld HPEC WG meeting, December 9, 2014 Goals Use cases: Promote VSIP standard to a wider audience (SciPy users) Add more hardware acceleration to SciPy Allow VSIP

More information

PATTERN RECOGNITION AND MACHINE LEARNING

PATTERN RECOGNITION AND MACHINE LEARNING PATTERN RECOGNITION AND MACHINE LEARNING Slide Set 1: Introduction and the Basics of Python January 2018 Heikki Huttunen heikki.huttunen@tut.fi Laboratory of Signal Processing Tampere University of Technology

More information

LECTURE 22. Numerical and Scientific Computing Part 2

LECTURE 22. Numerical and Scientific Computing Part 2 LECTURE 22 Numerical and Scientific Computing Part 2 MATPLOTLIB We re going to continue our discussion of scientific computing with matplotlib. Matplotlib is an incredibly powerful (and beautiful!) 2-D

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

Partial Differential Equations II: 2D Laplace Equation on 5x5 grid

Partial Differential Equations II: 2D Laplace Equation on 5x5 grid Partial Differential Equations II: 2D Laplace Equation on 5x5 grid Sam Sinayoko Numerical Methods 5 Contents 1 Learning Outcomes 2 2 Introduction 3 3 Laplace equation in 2D 3 4 Discretisation 3 4.1 Meshing:

More information

Newton and Quasi-Newton Methods

Newton and Quasi-Newton Methods Lab 17 Newton and Quasi-Newton Methods Lab Objective: Newton s method is generally useful because of its fast convergence properties. However, Newton s method requires the explicit calculation of the second

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

python numpy tensorflow tutorial

python numpy tensorflow tutorial python numpy tensorflow tutorial September 11, 2016 1 What is Python? From Wikipedia: - Python is a widely used high-level, general-purpose, interpreted, dynamic programming language. - Design philosophy

More information

#To import the whole library under a different name, so you can type "diff_name.f unc_name" import numpy as np import matplotlib.

#To import the whole library under a different name, so you can type diff_name.f unc_name import numpy as np import matplotlib. In [1]: #Here I import the relevant function libraries #This can be done in many ways #To import an entire library (e.g. scipy) so that functions accessed by typing "l ib_name.func_name" import matplotlib

More information

NumPy User Guide. Release dev7335. Written by the NumPy community

NumPy User Guide. Release dev7335. Written by the NumPy community NumPy User Guide Release 1.4.0.dev7335 Written by the NumPy community August 28, 2009 CONTENTS 1 Building and installing NumPy 3 1.1 Binary installers............................................. 3 1.2

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

Visualisation in python (with Matplotlib)

Visualisation in python (with Matplotlib) Visualisation in python (with Matplotlib) Thanks to all contributors: Ag Stephens, Stephen Pascoe. Introducing Matplotlib Matplotlib is a python 2D plotting library which produces publication quality figures

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

Introduction to Data Science. Introduction to Data Science with Python. Python Basics: Basic Syntax, Data Structures. Python Concepts (Core)

Introduction to Data Science. Introduction to Data Science with Python. Python Basics: Basic Syntax, Data Structures. Python Concepts (Core) Introduction to Data Science What is Analytics and Data Science? Overview of Data Science and Analytics Why Analytics is is becoming popular now? Application of Analytics in business Analytics Vs Data

More information

Python Tutorial. CS/CME/BioE/Biophys/BMI 279 Oct. 17, 2017 Rishi Bedi

Python Tutorial. CS/CME/BioE/Biophys/BMI 279 Oct. 17, 2017 Rishi Bedi Python Tutorial CS/CME/BioE/Biophys/BMI 279 Oct. 17, 2017 Rishi Bedi 1 Python2 vs Python3 Python syntax Data structures Functions Debugging Classes The NumPy Library Outline 2 Many examples adapted from

More information

pythonocc Parametric Application Framework (PAF) tutorial r0.4

pythonocc Parametric Application Framework (PAF) tutorial r0.4 pythonocc Parametric Application Framework (PAF) tutorial r0.4 Thomas Paviot (tpaviot@gmail.com) February 27, 2010 Abstract This guide aims at introducing in a few stages the pythonocc package intended

More information