The SciPy Stack. Jay Summet

Size: px
Start display at page:

Download "The SciPy Stack. Jay Summet"

Transcription

1 The SciPy Stack Jay Summet May 1, 2014

2 Outline Numpy - Arrays, Linear Algebra, Vector Ops MatPlotLib - Data Plotting SciPy - Optimization, Scientific functions TITLE OF PRESENTATION 2

3 What is Numpy? 3rd party module that extends the Python language Matrix and linear algebra operations General support for N-Dimensional Arrays Heterogeneous elements Direct mapping to C/C++/Fortran memory buffers Matrix operations Vectorized Algorithms Bindings to C and Fortran matrix math libraries Requires compiled support libraries Installers are platform specific 3

4 Importing Numpy Must install it via the SciPy stack or individually Most people import the numpy library as np Arrays can be created from lists or nested lists >>> import numpy as np >>> x = np.array( [1,5,10] ) >>> x array( [1, 5, 10] ) >>> y = np.array( [ [1,2,3], [4,5,6] ] ) >>> y array( [ [1,2,3], [4,5,6] ) 4

5 Data Types Numpy stores all data in an array using a single data type Direct mapping to memory / space required The Python data types have default mappings You will most commonly use: bool - boolean, stored as a byte int_ (Same as C long, either int32 or int64, architecture dependent) float_ ( float64) complex_ (complex128) Will convert python int/float/bool/complex automatically 5

6 Data Types Numpy supports many different native data types Will convert python int/float/bool/complex automatically The.dtype attribute of an array tells the actual data type Can convert to another data type using.astype() >>> x = np.array( [1,5,10] ) >>> x array( [1, 5, 10] ) >>> x.dtype dtype( int32 ) >>> y = x.astype(np.float64) >>> y array( [ 1., 5., 10.] ) >>> y.dtype dtype('float64') 6

7 Numpy Array Creation Convert python array-like data structures Using built in array creation methods: np.zeros ( shape ) np.ones( shape ) np.arange(start, Stop, step) - Like python range np.linspace( Start, Stop, number) Most accept an optional dtype parameter >>> x = np.zeros( (2,2), dtype=np.int_ ) >>> x array( [0, 0], [0, 0] ) >>> y = np.linspace( 1, 4, 6 ) >>> y array( [ 1., 1.6, 2.2, 2.8, 3.4, 4. ] ) 7

8 Array = Block of Memory All data in the array is stored in a single block of memory The.shape attribute stores the size of each dimension You can change the shape on the fly! must retain the exact number of elements A 1 x 10 array and a 2 x 5 array both have 10 data items >>> x = np.arange(10) >>> x array( [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] ) >>> x.shape (10, ) >>> x.shape = (2,5) >>> x array( [ 0, 1, 2, 3, 4], [ 5, 6, 7, 8, 9] ] ) 8

9 Array Indexing Works like indexing in python Zero based negative indexes count from the back BUT, You CAN index all dimensions at once if you want! >>> x = np.arange(10) >>> x[-1] 9 >>> x.shape = (2,5) >>> x[1][3] 8 >>>x[1,3] 8 9

10 Array Slicing Works like indexing in python Provide a Start:Stop:Stride Can do this for multiple dimensions at once >>> x = np.arange(25).reshape(5,5) >>> x array([[ 0, 1, 2, 3, 4], [ 5, 6, 7, 8, 9], [10, 11, 12, 13, 14], [15, 16, 17, 18, 19], [20, 21, 22, 23, 24] ] ) >>> x[0:5:2, 2:4] array([[ 2, 3], [12, 13], [22, 23] ] ) 10

11 Array Slicing - Aliasing! Slices provide VIEWS Like an alias of a list See array indexing if you want to copy a subset of data! >>> y = x[0:5:2, 2:4] >>> y[0,0] = 999 >>> y array([[999, 3], [ 12, 13], [ 22, 23]]) >>> x array([[ 0, 1, 999, 3, 4], [ 5, 6, 7, 8, 9], [ 10, 11, 12, 13, 14], [ 15, 16, 17, 18, 19], [ 20, 21, 22, 23, 24]]) 11

12 Advanced Indexing You can specify a set of indices with an array to select a copy of the data. >>> x array([ 0, 5, 10, 15, 20, 25]) >>> y = x[ np.array( [1,3,5] ) ] >>> y array([ 5, 15, 25]) >>> y[0] = 99 >>> y array( [99,15,25] >>> x array( [ 0, 5, 10, 15, 20, 25] ) 12

13 Advanced Indexing BUT, if you assign to an array indexing operation, it modifies the original... >>> x array([ 0, 5, 10, 15, 20, 25]) >>> y = x[ np.array( [1,3,5] ) ] >>> y array([ 5, 15, 25]) >>> x[ np.array( [1,3,5] ) ] += 1 >>> x array([ 0, 6, 10, 16, 20, 26]) >>> 13

14 Array Broadcasting Element-by-element operations on two arrays typically require the arrays to have the same shape A scaler is treated as a 1x1 array that gets broadcast over all elements >>> y = np.arange(1,5) >>> y array([1, 2, 3, 4]) >>> y * 2 array([2, 4, 6, 8], dtype=int32) >>> y * 2. array([ 2., 4., 6., 8.]) 14

15 Array Broadcasting Arrays that are short in a dimension can also be broadcast! The Rule: In order to broadcast, the size of the trailing axes for both arrays in an operation must either be the same size or one of them must be one. >>> a = np.array( [ [0, 1, 2], [3, 4, 5] ] ) >>> b = np.array( [4,5,6] ) >>> c = a * b #Multiplication, not np.dot(a,b) >>> c array( [ [ 0, 5, 12], [12, 20, 30] ], dtype=int32) 15

16 Vector Algorithms: Calculating y = sin(x), for 100 elements between -4 and 4 >>> x = np.linspace(-4,4,100) >>> y = np.sin(x) 16

17 What is Matplotlib? Python library that supports plotting data Many features were copied from MATLAB Easily produce Graphs/Plots of Lines Histograms Bargraphs Scatterplots 3D surfaces 17

18 Plotting sin data Plotting 2D data (x vs y) requires two lines of code Three if you count the import... import numpy as np import matplotlib.pyplot as plt x = np.linspace(-4,4,100) y = np.sin(x) temp = plt.plot(x,y) plt.show() 18

19 Filled Plot import numpy as np import matplotlib.pyplot as plt x = np.linspace(-np.pi, np.pi,100) y = np.sin(x) temp = plt.fill(x,y, color="green") plt.grid(true) plt.show() 19

20 Other plots Pie charts import matplotlib.pyplot as plt labels = [ 'Red', 'Green', 'Blue', 'Yellow' ] colors = [ 'red', 'lightgreen', 'lightskyblue', 'gold'] values = [3,4,10,1] explode = (0.2, 0, 0, 0) plt.pie(values, explode=explode, colors=colors, labels=labels, shadow=true, autopct='%1.1f%%') plt.show() 20

21 3D Plots require 3D data Numpy meshgrid function allows you to create arrays with all possible X or Y coordinates >>> x = np.arange(0,5,1) >>> y = np.arange(0,4,1) >>> x array([0, 1, 2, 3, 4]) >>> y array([0, 1, 2, 3]) >>> NX,NY = np.meshgrid(x,y) >>> NX array([[0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4]]) >>> NY array([[0, 0, 0, 0, 0], [1, 1, 1, 1, 1], [2, 2, 2, 2, 2], [3, 3, 3, 3, 3]]) 21

22 3D Plots require 3D data These arrays can be used to calculate a 3rd (Z) axis based upon a formula, such as euclidean distance from origin. Note the distance at point (4,3) is 5 (3x4x5 triangle) >>> D = np.sqrt( NX**2 + NY**2 ) >>> D array([[ 0., 1., 2., 3., 4. ], [ 1., , , , ], [ 2., , , , ], [ 3., , , , 5. ]]) >>> 22

23 3D Plots require 3D data And you could calculate the sin of the distance... >>> Z = np.sin(d) >>> Z array([[ 0., , , , ], [ , , , , ], [ , , , , ], [ , , , , ]]) 23

24 3D surface Plot >>> import matplotlib.pyplot as plt >>> from mpl_toolkits.mplot3d import Axes3D >>> fig = plt.figure() >>> ax = fig.gca(projection='3d') #Requires Axes3D import! >>> surf = ax.plot_surface(nx,ny, Z, rstride=1, cstride=1, linewidth=0 ) >>> plt.show() 24

25 Surface Plot - more points import numpy as np X = np.arange(-5, 5, 0.1) Y = np.arange(-5, 5, 0.1) NX,NY = np.meshgrid(x, Y) D = np.sqrt(nx**2 + NY**2) Z = np.sin(d) import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D fig = plt.figure() ax = fig.gca(projection='3d') surf = ax.plot_surface(nx,ny, Z, rstride=1, cstride=1, linewidth=0 ) plt.show() 25

26 Adding more bling... Add a colormap and colorbar (key) Customizing the Z axis 26

27 Colormap & Z-axis scale from matplotlib.ticker import LinearLocator, FormatStrFormatter from matplotlib import cm... ax = fig.gca(projection='3d') surf = ax.plot_surface(nx,ny, Z, rstride=1, cstride=1, linewidth=0, cmap=cm.coolwarm ) #Colorbar requires the surface to have a colormap. fig.colorbar(surf, shrink=0.5, aspect=5) #Customize Z-axis ax.set_zlim(-1.01, 1.01) ax.zaxis.set_major_locator(linearlocator(10)) ax.zaxis.set_major_formatter(formatstrformatter('%.02f')) 27

28 What is SciPy? Python library that builds upon Numpy arrays Provides higher level math support for Optimization Linear Algebra Interpolation FFT Ordinary Differential Equation Solvers 28

29 SciPy Function minimization Classic example function: Rosenbrock Source code in handout: rosenbrock_demo.py 29

30 Function Minimization Define the function to accept a sequence (of parameters) def rosenbrock(parms): x,y = parms return (1-x)** * (y-x**2)**2 Source code in handout: rosenbrock_minimum.py 30

31 Function Minimization Import and call fmin from scipy.optimize Provide a starting point, and GO! import numpy as np from scipy.optimize import fmin x0 = np.array( [4,-3]) #Try starting at (4,-3) res = fmin( rosenbrock, x0, xtol=1e-8) print res Source code in handout: rosenbrock_minimum.py 31

32 Function Minimization Optimization terminated successfully. Current function value: Iterations: 90 Function evaluations: 174 [ 1. 1.] Source code in handout: rosenbrock_minimum.py 32

33 Fin Questions? 33

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Introduction to Matplotlib: 3D Plotting and Animations

Introduction to Matplotlib: 3D Plotting and Animations 1 Introduction to Matplotlib: 3D Plotting and Animations Lab Objective: 3D plots and animations are useful in visualizing solutions to ODEs and PDEs found in many dynamics and control problems. In this

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

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

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

(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

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

Exercise: Introduction to NumPy arrays

Exercise: Introduction to NumPy arrays Exercise: Introduction to NumPy arrays Aim: Introduce basic NumPy array creation and indexing Issues covered: Importing NumPy Creating an array from a list Creating arrays of zeros or ones Understanding

More information

mpl Release latest May 17, 2017

mpl Release latest May 17, 2017 mpl a nimationmanagerdocumentation Release latest May 17, 2017 Contents 1 NOTE: Documentation is curently in development!!! 1 1.1 Matplotlib animation manager (GUI) 1.0a1...............................

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

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

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

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

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

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

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

#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

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

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

More information

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

Session 1 Use test driven development (i.e. write the tests first) to design functions to give the square, cube and an arbitary power N for a number a. In [1]: import unittest def square(a): return a**2

More information

CS 237 Lab Nine: Displaying Multivariate Data

CS 237 Lab Nine: Displaying Multivariate Data CS 237 Lab Nine: Displaying Multivariate Data Due date: PDF file due Thursday November 15st @ 11:59PM (10% off if up to 24 hours late) in GradeScope General Instructions Please complete this notebook by

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

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

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

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

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

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

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

Derek Bridge School of Computer Science and Information Technology University College Cork CS468: Artificial Intelligence I Ordinary Least Squares Regression Derek Bridge School of Computer Science and Information Technology University College Cork Initialization In [4]: %load_ext autoreload

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

Implement NN using NumPy

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

More information

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

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

More information

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

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

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

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

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

HW2. October 24, CSE 252A Computer Vision I Fall Assignment 2

HW2. October 24, CSE 252A Computer Vision I Fall Assignment 2 HW2 October 24, 2018 1 CSE 252A Computer Vision I Fall 2018 - Assignment 2 1.0.1 Instructor: David Kriegman 1.0.2 Assignment Published On: Wednesday, October 24, 2018 1.0.3 Due On: Wednesday, November

More information

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

NumPy User Guide. Release dev7072. Written by the NumPy community NumPy User Guide Release 1.4.0.dev7072 Written by the NumPy community June 24, 2009 CONTENTS 1 Building and installing NumPy 3 1.1 Binary installers............................................. 3 1.2

More information

Activity recognition and energy expenditure estimation

Activity recognition and energy expenditure estimation Activity recognition and energy expenditure estimation A practical approach with Python WebValley 2015 Bojan Milosevic Scope Goal: Use wearable sensors to estimate energy expenditure during everyday activities

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

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

Python Programming, bridging course 2011

Python Programming, bridging course 2011 Python Programming, bridging course 2011 About the course Few lectures Focus on programming practice Slides on the homepage No course book. Using online resources instead. Online Python resources http://www.python.org/

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

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

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

Computational Physics Programming Style and Practices & Visualizing Data via Plotting

Computational Physics Programming Style and Practices & Visualizing Data via Plotting Computational Physics Programming Style and Practices & Visualizing Data via Plotting Prof. Paul Eugenio Department of Physics Florida State University Jan 30, 2018 http://comphy.fsu.edu/~eugenio/comphy/

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

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

Python in Scientific Computing

Python in Scientific Computing Jussi Enkovaara import sys, os try: from Bio.PDB import PDBParser biopython_installed = True except ImportError: biopython_installed = False Python in Scientific Computing June 10, 2014 Scientific computing

More information

Practical Numpy and Matplotlib Intro

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

More information

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

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

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

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

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

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

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

Building Geometries in Data Arrays

Building Geometries in Data Arrays EE 5303 Electromagnetic Analysis Using Finite Difference Time Domain Lecture #3 Building Geometries in Data Arrays Lecture 3 Slide 1 Lecture Outline MATLAB Data and Arrays 3D 2D 1D Building Geometries

More information

Topic 2b Building Geometries into Data Arrays

Topic 2b Building Geometries into Data Arrays Course Instructor Dr. Raymond C. Rumpf Office: A 337 Phone: (915) 747 6958 E Mail: rcrumpf@utep.edu Topic 2b Building Geometries into Data Arrays EE 4386/5301 Computational Methods in EE Outline Visualizing

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

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

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

Somoclu Python Documentation

Somoclu Python Documentation Somoclu Python Documentation Release 1.7.5 Peter Wittek, Shi Chao Gao Mar 01, 2018 Contents 1 Introduction 1 1.1 Copyright and License.......................................... 1 1.2 Acknowledgment.............................................

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

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

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

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

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

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

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

PS6-DCT-Soln-correction

PS6-DCT-Soln-correction PS6-DCT-Soln-correction Unknown Author March 18, 2014 Part I DCT: Discrete Cosine Transform DCT is a linear map A R N N such that the N real numbers x 0,..., x N 1 are transformed into the N real numbers

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

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