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

Size: px
Start display at page:

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

Transcription

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

2 Support for large, multi-dimensional arrays and matrices, and a large library of high-level mathematical functions to operate on these arrays Support for scientific computing: optimization, linear algebra, integration, interpolation, statistics, FFT, signal and image processing, etc. Based heavily on NumPy Plotting library, designed especially for use with NumPy, with MatLab-like interface 4/4/16 2

3 NumPy, SciPy, matplotlib Centrally managed on Abel Tight mutual integration Powerful set of tools for data analysis and visualization Usually available on every scientific resource Easy to learn and use The 3 pieces used together can replace MATLAB. 4/4/16 3

4 Getting started on Abel For interactive use: -bash-4.1$ module load python2 -bash-4.1$ module load python2 -bash-4.1$ python -bash-4.1$ python Python (default, Jul , Python (default, Jul , 11:02:23) 11:02:23) [GCC Intel(R) C++ gcc 4.4 mode] [GCC Intel(R) C++ gcc 4.4 mode] on linux2 on linux2 Type "help", "copyright", "credits" or Type "help", "copyright", "credits" or "license" for more information. "license" for more information. >>> import numpy >>> import numpy >>> import scipy >>> import scipy >>> import matplotlib >>> import matplotlib However, you'd rather use matplotlib as >>> >>> 4/4/16 4

5 Numpy General documentation Routines index SciPY Matplotlib 4/4/16 5

6 Numpy arrays >>> import numpy as np >>> import numpy as np >>> cvalues = [25.3, 24.8, 26.9, 23.9] >>> cvalues = [25.3, 24.8, 26.9, 23.9] >>> C = np.array(cvalues) >>> C = np.array(cvalues) >>> print(c) >>> print(c) [ ] [ ] >>> print(c * 9 / ) >>> print(c * 9 / ) [ ] [ ] # Indexing and slicing similar to python lists # Indexing and slicing similar to python lists >>> print C[0] >>> print C[0] >>> print C[1:3] >>> print C[1:3] More straightforward syntax than with lists Considerably faster 4/4/16 6

7 Numpy arrays: advanced addressing and slicing >>> A = np.array([ [3.4, 8.7, 9.9], [1.1, -7.8, -0.7], [4.1, 12.3, 4.8] ]) >>> A = np.array([ [3.4, 8.7, 9.9], [1.1, -7.8, -0.7], [4.1, 12.3, 4.8] ]) >>> print(a[1, 0]) >>> print(a[1, 0]) >>> A = np.array([ >>> A = np.array([... [11,12,13,14,15],... [11,12,13,14,15],... [21,22,23,24,25],... [21,22,23,24,25],... [31,32,33,34,35],... [31,32,33,34,35],... [41,42,43,44,45],... [41,42,43,44,45],... [51,52,53,54,55] ] )... [51,52,53,54,55] ] ) >>> print(a[:3,2:]) >>> print(a[:3,2:]) [[ ] [[ ] [ ] [ ] [ ]] [ ]] 4/4/16 7

8 Numpy arrays: advanced slicing (using step) [start:stop:step] >>> A = np.array([ [ ] >>> A = np.array([ [ ]... [ ]... [ ]... [ ]... [ ]... [ ] ] )... [ ] ] ) >>> print (A[::2, ::3]) >>> print (A[::2, ::3]) [[ 0 3 6] [[ 0 3 6] [ ]] [ ]] >>> print(a[::2, ::3]) >>> print(a[::2, ::3]) [[ 0 3 6] [[ 0 3 6] [ ]] [ ]] 4/4/16 8

9 Numpy arrays: evenly spaced values >>> a = np.arange(1, 10) >>> a = np.arange(1, 10) >>> print(a) >>> print(a) [ ] [ ] >>> x = np.arange(0.5, 10.4, 0.8) >>> x = np.arange(0.5, 10.4, 0.8) >>> print(x) >>> print(x) [ ] [ ] >>> print(np.linspace(1, 10)) >>> print(np.linspace(1, 10)) [ [ ] ] 4/4/16 9

10 Numpy arrays: reshaping >>> x = np.array([ [67, 63, 87], [77, 69, 59], [85, 87, 99], [79, 72, 71], [63, 89, 93], [68, 92, 78]]) >>> x = np.array([ [67, 63, 87], [77, 69, 59], [85, 87, 99], [79, 72, 71], [63, 89, 93], [68, 92, 78]]) >>> print(np.shape(x)) >>> print(np.shape(x)) (6, 3) (6, 3) >>> x.shape = (3, 6) >>> x.shape = (3, 6) >>> print(x) >>> print(x) [[ ] [[ ] [ ] [ ] [ ]] [ ]] >>> X = np.arange(28).reshape(4,7) >>> X = np.arange(28).reshape(4,7) >>> print(x) >>> print(x) [[ ] [[ ] [ ] [ ] [ ] [ ] [ ]] [ ]] 4/4/16 10

11 Scipy statistics >>> from scipy import stats >>> from scipy import stats # Probability density function # Probability density function >>> stats.norm.pdf(0.5) >>> stats.norm.pdf(0.5) # Cumulative distribution function # Cumulative distribution function >>> stats.norm.cdf(0.5) >>> stats.norm.cdf(0.5) # Typical statistics functions # Typical statistics functions >>> norm.mean() >>> norm.mean() >>> norm.median() >>> norm.median() >>> norm.std() >>> norm.std() /4/16 11

12 Scipy statistics >>> a = np.array([1,2,3,4]) >>> a = np.array([1,2,3,4]) >>> b = np.array([10,9,8,7]) >>> b = np.array([10,9,8,7]) # Pearson correlation coefficient # Pearson correlation coefficient >>> stats.pearsonr(a, b) >>> stats.pearsonr(a, b) (-1.0, 0.0) (-1.0, 0.0) # Measure Kolmogorov-Smirnov distance between two samples # Measure Kolmogorov-Smirnov distance between two samples >>> stats.ks_2samp(a,b) >>> stats.ks_2samp(a,b) Ks_2sampResult(statistic=1.0, pvalue= ) Ks_2sampResult(statistic=1.0, pvalue= ) # Maximum Likelihood Estimation # Maximum Likelihood Estimation >>> a=np.array([0.1, 0.2, 0.3, 0.4, 0.5]) >>> a=np.array([0.1, 0.2, 0.3, 0.4, 0.5]) >>> stat.norm.fit(a) >>> stat.norm.fit(a) ( , ) ( , ) 4/4/16 12

13 matplotlib plt.plot([1,2,3,4]) plt.plot([1,2,3,4]) plt.ylabel('some numbers') plt.ylabel('some numbers') 4/4/16 13

14 matplotlib plt.plot([1,2,3,4], [1,4,9,16]) plt.plot([1,2,3,4], [1,4,9,16]) 4/4/16 14

15 matplotlib plt.plot([1,2,3,4], [1,4,9,16], 'ro') plt.plot([1,2,3,4], [1,4,9,16], 'ro') plt.axis([0, 6, 0, 20]) plt.axis([0, 6, 0, 20]) 4/4/16 15

16 matplotlib import numpy as np import numpy as np t = np.arange(0., 5., 0.2) t = np.arange(0., 5., 0.2) plt.plot(t, t, 'r--', t, t**2, 'bs', t, t**3, 'g^') plt.plot(t, t, 'r--', t, t**2, 'bs', t, t**3, 'g^') 4/4/16 16

17 matplotlib import numpy as np import numpy as np mu, sigma = 100, 15 mu, sigma = 100, 15 x = mu + sigma * np.random.randn(10000) x = mu + sigma * np.random.randn(10000) n, bins, patches = plt.hist(x, 50, normed=1, facecolor='g', alpha=0.75) n, bins, patches = plt.hist(x, 50, normed=1, facecolor='g', alpha=0.75) plt.xlabel('smarts') plt.xlabel('smarts') plt.ylabel('probability') plt.ylabel('probability') plt.title('histogram of IQ') plt.title('histogram of IQ') plt.text(60,.025, r'$\mu=100,\ \sigma=15$') plt.text(60,.025, r'$\mu=100,\ \sigma=15$') plt.axis([40, 160, 0, 0.03]) plt.axis([40, 160, 0, 0.03]) plt.grid(true) plt.grid(true) 4/4/16 17

18 matplotlib plt.scatter([x[0] for x in alldata],[x[1] for x in alldata],s=5,marker='+',c='b') plt.scatter([x[0] for x in alldata],[x[1] for x in alldata],s=5,marker='+',c='b') plt.text(200000,6000,"pearson coef = %.3f" % stat.pearsonr([x[0] for x in alldata],[x[1] for x in alldata])[0]) plt.text(200000,6000,"pearson coef = %.3f" % stat.pearsonr([x[0] for x in alldata],[x[1] for x in alldata])[0]) 4/4/16 18

19 matplotlib For non-interactive use: import matplotlib as mpl import matplotlib as mpl mpl.use('agg') mpl.use('agg') now use as usual......but don't forget to save the picture instead of showing x = np.arange(0, 3 * np.pi, 0.1) x = np.arange(0, 3 * np.pi, 0.1) y = np.sin(x) y = np.sin(x) plt.plot(x, y) plt.plot(x, y) plt.savefig("plt_test.png") plt.savefig("plt_test.png") 4/4/16 19

20 Example import numpy as np import numpy as np from scipy.stats import norm from scipy.stats import norm import matplotlib import matplotlib matplotlib.use('agg') matplotlib.use('agg') a = np.array([1, 2, 3]) # Create a rank 1 array a = np.array([1, 2, 3]) # Create a rank 1 array print type(a) # Prints "<type 'numpy.ndarray'>" print type(a) # Prints "<type 'numpy.ndarray'>" print a.shape # Prints "(3,)" print a.shape # Prints "(3,)" print a[0], a[1], a[2] # Prints "1 2 3" print a[0], a[1], a[2] # Prints "1 2 3" a[0] = 5 # Change an element of the array a[0] = 5 # Change an element of the array print a print a print " " print " " print norm.cdf(0) print norm.cdf(0) print " " print " " x = np.arange(0, 3 * np.pi, 0.1) x = np.arange(0, 3 * np.pi, 0.1) y = np.sin(x) y = np.sin(x) # Plot the points using matplotlib # Plot the points using matplotlib plt.plot(x, y) plt.plot(x, y) plt.savefig("plt_test.png") plt.savefig("plt_test.png") print "\ndone" print "\ndone" 4/4/16 20

21 Example #!/bin/bash #!/bin/bash #SBATCH --job-name=advanced_python_test #SBATCH --job-name=advanced_python_test #SBATCH --account=uio #SBATCH --account=uio #SBATCH --time=00:03:00 #SBATCH --time=00:03:00 #SBATCH --mem-per-cpu=4g #SBATCH --mem-per-cpu=4g #SBATCH --mail-type=all #SBATCH --mail-type=all ## Set up job environment: ## Set up job environment: source /cluster/bin/jobsetup source /cluster/bin/jobsetup module purge # clear any inherited modules module purge # clear any inherited modules module load python2 module load python2 set -o errexit # exit on errors set -o errexit # exit on errors ## Copy input files to the work directory: ## Copy input files to the work directory: cp -rf adv_python_test.py $SCRATCH cp -rf adv_python_test.py $SCRATCH ## Do some work: ## Do some work: cd $SCRATCH cd $SCRATCH python pyth.py python pyth.py cp plt_test.png $SUBMITDIR cp plt_test.png $SUBMITDIR 4/4/16 21

(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

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

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

CSCI5070 Advanced Topics in Social Computing

CSCI5070 Advanced Topics in Social Computing CSCI5070 Advanced Topics in Social Computing Python and APIs Irwin King The Chinese University of Hong Kong king@cse.cuhk.edu.hk 2012 All Rights Reserved. Tutorial Overview Python basics and APIs Web crawler

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

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

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

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

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

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

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

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

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

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

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

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

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

INF : NumPy and SciPy

INF : NumPy and SciPy INF5830 2015: NumPy and SciPy Python with extension packages have become one of the preferred tools for data science and machine learning. The packages NumPy and SciPy are backbones of this approach. We

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 Python

Introduction to Python Introduction to Python Jon Kerr Nilsen, Dmytro Karpenko Research Infrastructure Services Group, Department for Research Computing, USIT, UiO Why Python Clean and easy-to-understand syntax alldata = cpickle.load(open(filename1,

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

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

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

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

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

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

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

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

Exercises: Abel/Colossus and SLURM

Exercises: Abel/Colossus and SLURM Exercises: Abel/Colossus and SLURM November 08, 2016 Sabry Razick The Research Computing Services Group, USIT Topics Get access Running a simple job Job script Running a simple job -- qlogin Customize

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

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

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

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

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 Python. Dmytro Karpenko Research Infrastructure Services Group, Department for Research Computing, USIT, UiO

Introduction to Python. Dmytro Karpenko Research Infrastructure Services Group, Department for Research Computing, USIT, UiO Introduction to Python Dmytro Karpenko Research Infrastructure Services Group, Department for Research Computing, USIT, UiO Research Computing Services tutorial and courses November 3-7, 2014 Why python

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

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

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

python 01 September 16, 2016

python 01 September 16, 2016 python 01 September 16, 2016 1 Introduction to Python adapted from Steve Phelps lectures - (http://sphelps.net) 2 Python is interpreted Python is an interpreted language (Java and C are not). In [1]: 7

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

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

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

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

Python Tutorial for CSE 446

Python Tutorial for CSE 446 Python Tutorial for CSE 446 Kaiyu Zheng, David Wadden Department of Computer Science & Engineering University of Washington January 2017 Goal Know some basics about how to use Python. See how you may use

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

Python Tutorial for CSE 446

Python Tutorial for CSE 446 Python Tutorial for CSE 446 Kaiyu Zheng, Fanny Huang Department of Computer Science & Engineering University of Washington January 2018 Goal Know some basics about how to use Python. See how you may use

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

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

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

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

CME 193: Introduction to Scientific Python Lecture 5: Object Oriented Programming

CME 193: Introduction to Scientific Python Lecture 5: Object Oriented Programming CME 193: Introduction to Scientific Python Lecture 5: Object Oriented Programming Nolan Skochdopole stanford.edu/class/cme193 5: Object Oriented Programming 5-1 Contents Classes Numpy Exercises 5: Object

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

Slurm and Abel job scripts. Katerina Michalickova The Research Computing Services Group SUF/USIT October 23, 2012

Slurm and Abel job scripts. Katerina Michalickova The Research Computing Services Group SUF/USIT October 23, 2012 Slurm and Abel job scripts Katerina Michalickova The Research Computing Services Group SUF/USIT October 23, 2012 Abel in numbers Nodes - 600+ Cores - 10000+ (1 node->2 processors->16 cores) Total memory

More information

Slurm and Abel job scripts. Katerina Michalickova The Research Computing Services Group SUF/USIT November 13, 2013

Slurm and Abel job scripts. Katerina Michalickova The Research Computing Services Group SUF/USIT November 13, 2013 Slurm and Abel job scripts Katerina Michalickova The Research Computing Services Group SUF/USIT November 13, 2013 Abel in numbers Nodes - 600+ Cores - 10000+ (1 node->2 processors->16 cores) Total memory

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

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

Using Python for research and acoustic signal processing

Using Python for research and acoustic signal processing processing Axel Plinge Pattern Recognition, Computer Science XII, TU Dortmund University October 2015 Bar-Ilan University Motivation (1) processing 1/15 Why use Python? it s free cross platform (Windows,

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

Computational Physics

Computational Physics Computational Physics Objects : Lists & Arrays Prof. Paul Eugenio Department of Physics Florida State University Jan 24, 2019 http://hadron.physics.fsu.edu/~eugenio/comphy/ Announcements Read chapter 3

More information

Intro to Research Computing with Python: Visualization

Intro to Research Computing with Python: Visualization Intro to Research Computing with Python: Visualization Erik Spence SciNet HPC Consortium 20 November 2014 Erik Spence (SciNet HPC Consortium) Visualization 20 November 2014 1 / 29 Today s class Today we

More information

import matplotlib as mpl # As of July 2017 Bucknell computers use v. 2.x import matplotlib.pyplot as plt

import matplotlib as mpl # As of July 2017 Bucknell computers use v. 2.x import matplotlib.pyplot as plt PHYS 310 HW Problem Simulation of PHYS 211 M&M Experiment 6 Colors: Yellow, Blue, Orange, Red, Green, and Blue Assume 60 M&Ms in every bag Assume equal probabilities (well mixed, large "reservoir") Assume

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

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

L3-Python-for-Statistical-Modeling

L3-Python-for-Statistical-Modeling L3-Python-for-Statistical-Modeling October 16, 2015 1 Python modules for Statistics 1.1 NumPy NumPy is short for Numerical Python, is the foundational package for scientific computing in Python. It contains

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

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

MAS212 Scientific Computing and Simulation

MAS212 Scientific Computing and Simulation MAS212 Scientific Computing and Simulation Dr. Sam Dolan School of Mathematics and Statistics, University of Sheffield Autumn 2017 http://sam-dolan.staff.shef.ac.uk/mas212/ G18 Hicks Building s.dolan@sheffield.ac.uk

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

zap Documentation Release 1.0.dev86 Kurt Soto

zap Documentation Release 1.0.dev86 Kurt Soto zap Documentation Release 1.0.dev86 Kurt Soto February 03, 2016 Contents 1 Installation 3 1.1 Requirements............................................... 3 1.2 Steps...................................................

More information

Python on GACRC Computing Resources

Python on GACRC Computing Resources Python on GACRC Computing Resources Georgia Advanced Computing Resource Center EITS/University of Georgia Zhuofei Hou, zhuofei@uga.edu 1 Outline GACRC Python Overview Python on Clusters Python Packages

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

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

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

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

solving polynomial systems in the cloud with phc

solving polynomial systems in the cloud with phc solving polynomial systems in the cloud with phc Jan Verschelde University of Illinois at Chicago Department of Mathematics, Statistics, and Computer Science http://www.math.uic.edu/ jan jan@math.uic.edu

More information

Using jupyter notebooks on Blue Waters. Roland Haas (NCSA / University of Illinois)

Using jupyter notebooks on Blue Waters.   Roland Haas (NCSA / University of Illinois) Using jupyter notebooks on Blue Waters https://goo.gl/4eb7qw Roland Haas (NCSA / University of Illinois) Email: rhaas@ncsa.illinois.edu Jupyter notebooks 2/18 interactive, browser based interface to Python

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

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

Adina Howe Instructor

Adina Howe Instructor INTRO TO PYTHON FOR FINANCE Arrays Adina Howe Instructor Installing packages pip3 install package_name_here pip3 install numpy Importing packages import numpy NumPy and Arrays import numpy my_array = numpy.array([0,

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

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

Python: Swiss-Army Glue. Josh Karpel Graduate Student, Yavuz Group UW-Madison Physics Department

Python: Swiss-Army Glue. Josh Karpel Graduate Student, Yavuz Group UW-Madison Physics Department 1 Python: Swiss-Army Glue Josh Karpel Graduate Student, Yavuz Group UW-Madison Physics Department My Research: Matrix Multiplication 2 My Research: Computational Quantum Mechanics 3 Why

More information

A New Cyberinfrastructure for the Natural Hazards Community

A New Cyberinfrastructure for the Natural Hazards Community A New Cyberinfrastructure for the Natural Hazards Community 1 Agenda Introduction to the Jupyter Notebook Programming in Python Plotting with Matplotlib Putting everything together a scientific notebook

More information

Sampling from distributions

Sampling from distributions Sampling from distributions December 17, 2015 1 Sampling from distributions Now that we are able to sample equally distributed (pseudo-)random numbers in the interval [1, 0), we are now able to sample

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

MS&E351 Dynamic Programming and Stochastic Control Autumn 2016 Professor Benjamin Van Roy Python Tutorial

MS&E351 Dynamic Programming and Stochastic Control Autumn 2016 Professor Benjamin Van Roy Python Tutorial MS&E351 Dynamic Programming and Stochastic Control Autumn 2016 Professor Benjamin Van Roy 20160927 Python Tutorial In this course, we will use the python programming language and tools that support dynamic

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

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

NAG at Manchester. Michael Croucher (University of Manchester)

NAG at Manchester. Michael Croucher (University of Manchester) NAG at Manchester Michael Croucher (University of Manchester) Michael.Croucher@manchester.ac.uk www.walkingrandomly.com Twitter: @walkingrandomly My background PhD Computational Physics from Sheffield

More information

Lab 4 S Objectives. The string type. Exercise 0

Lab 4 S Objectives. The string type. Exercise 0 Lab 4 S2 2017 Lab 4 Note: There may be more exercises in this lab than you can finish during the lab time. If you do not have time to finish all exercises (in particular, the programming problems), you

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

Command Line and Python Introduction. Jennifer Helsby, Eric Potash Computation for Public Policy Lecture 2: January 7, 2016

Command Line and Python Introduction. Jennifer Helsby, Eric Potash Computation for Public Policy Lecture 2: January 7, 2016 Command Line and Python Introduction Jennifer Helsby, Eric Potash Computation for Public Policy Lecture 2: January 7, 2016 Today Assignment #1! Computer architecture Basic command line skills Python fundamentals

More information

L15. 1 Lecture 15: Data Visualization. July 10, Overview and Objectives. 1.2 Part 1: Introduction to matplotlib

L15. 1 Lecture 15: Data Visualization. July 10, Overview and Objectives. 1.2 Part 1: Introduction to matplotlib L15 July 10, 2017 1 Lecture 15: Data Visualization CSCI 1360E: Foundations for Informatics and Analytics 1.1 Overview and Objectives Data visualization is one of, if not the, most important method of communicating

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

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

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

ME30_Lab1_18JUL18. August 29, ME 30 Lab 1 - Introduction to Anaconda, JupyterLab, and Python

ME30_Lab1_18JUL18. August 29, ME 30 Lab 1 - Introduction to Anaconda, JupyterLab, and Python ME30_Lab1_18JUL18 August 29, 2018 1 ME 30 Lab 1 - Introduction to Anaconda, JupyterLab, and Python ME 30 ReDev Team 2018-07-18 Description and Summary: This lab introduces Anaconda, JupyterLab, and Python.

More information