Practical Numpy and Matplotlib Intro
|
|
- Emil Parks
- 5 years ago
- Views:
Transcription
1 Practical Numpy and Matplotlib Intro presented by Tom Adelman, Sept 28, 2012 What is Numpy? Advantages of using Numpy In [ ]: # an example n = # Python a0 = [i for i in range(n)] time: memory: a1 = [a0[i]+1 for i in range(n)] time: memory: # Numpy b0 = np.arange(n) n= time: memory: b1 = b0 + 1 time: memory: less memory for the same amount of data (about 3-4x less for ints -- 4 for type pointer, 4 for reference count, 4 for value) faster (5-100x) convenient and expressive (e.g., x+1, and much more) functionality (random numbers, math, fancy slicing and indexing, convolutions, statistics, linear algebra, FFTs, etc, etc) Structure of a numpy array in memory In [23]: a0 = array([1, 2, 3, 4, 5], dtype=uint16) "a0:" a0, type(a0) repr(str(a0.data)) a0: [ ] <type 'numpy.ndarray'> '\x01\x00\x02\x00\x03\x00\x04\x00\x05\x00' In [153]: from IPython.core.display import Image as ipimage # just for displaying image in the notebook ipimage(filename='ndarray2.png') Out[153]: Implication: vectorize 1 of 17
2 Summary That is: Numpy = **Multidimensional Homogeneous Arrays** and tools to work with these arrays. Characteristics: 1) all the same type 2) fixed size 3) multidimensional: 1, 2, 3, 4,... 4) x + 1. means add 1 to each element of the array Gain a lot for these restrictions: speed, memory, functionality. Uses examples of uses: Astronomy Artificial intelligence & machine learning Bayesian Statistics Biology (including Neuroscience) Dynamical systems Economics and Econometrics Electromagnetics and Electrical Engineering Geosciences Molecular modeling Signal processing Symbolic math, number theory, etc. Why discuss Numpy (number crunching) and Matplotlib (data plotting together)? In [31]: data = [-.56,.39,.82, 1.47, 2.1] In [32]: plot(data, 'o') xlim(-.5, 4.5)... Always plot your numbers!!! matplotlib gallery page Numpy Basics running numpy ipython 2 of 17
3 In [22]: # to import numpy, do: from numpy import * # or do: import numpy as np # import matplotlib like this... import matplotlib.pyplot as plt # y = exp(sin(x)) # y = np.exp(np.sin(x)) creating ndarrays In [31]: array([1, 5, 10]) # not array(1, 5, 10) [1, 5, 10] [ ] [1, 5, 10] In [15]: zeros((2, 2)) # also ones [[ 0. 0.] [ 0. 0.]] In [25]: arange(10) [ ] In [44]: linspace(-pi, pi, 10) [ ] loadtxt, fromfile, fromstring,.npz files,... can easily read data from: csv, hdf5, R, Matlab, PIL, Excel files,... more basics... In [24]: x = ones((2,2,2), dtype=uint8) # dtype = data type [[[1 1] [1 1]] [[1 1] [1 1]]] In [25]: x[0, 0, 0] = 300 [[[44 1] [ 1 1]] [[ 1 1] [ 1 1]]] # two points: index using [], setting values doesn't conver type ndarray properties 3 of 17
4 In [7]: x = zeros((2,2), dtype=int32) In [8]:.shape (2, 2) In [9]:.dtype int32 basic math: +, -, *, /, ** operations are element-wise In [77]: # degrees Celsius c = linspace(0, 100., 10) c [ ] In [80]: f = (9./5)*c + 32 f [ ] In [30]: x = reshape(arange(4), (2, 2)) **2 [[0 1] [2 3]] [[0 1] [4 9]] In [84]: x = arange(10) y = arange(10) *y 10*x-y [ ] [ ] slicing and indexing [start:stop:step] method In [147]: x = arange(10) [2::2] [::-1] # indexing starts at zero # -1 step reverses direction [ ] [ ] [ ] 4 of 17
5 In [3]: x = arange(10, dtype=uint8) y = x[0:6:2] # slices are views, NOT copies y[2] = 100 y. array_interface ['data'][0], repr(str(x.data)) y. array_interface ['data'][0]#, repr(str(y.data)) [ ] [ ] '\x00\x01\x02\x03d\x05\x06\x07\x08\t' In [4]: z = reshape(x, (2,5)) # slicing and reshaping (if possible), just changes the header, not the z z. array_interface ['data'][0], repr(str(z.data)) [[ ] [ ]] '\x00\x01\x02\x03d\x05\x06\x07\x08\t' To sort out questions during the presentation, the rule of thumb is this: If the function changes the data in the array, then it will return a new array. Reshaping and slicing usually don't require changing the data, so they return a view when possible. To check if you have a copy use the base attribute (ie, y.base is x). By the way, many function have the "out" keyword, and this can be used to do the operation in place, if desired, so sin(x, "out"=x) will put the output of the calculation back into x. Mostly though, I use this not for in-place operations, but when trying to speed up code that's run multiple times. That is, outside the loop I create an array, temp = zeros(( ,)), and then in the loop run sin(x, "out"=temp), so I don't need to constantly recreate space for the output of sin(x). integer indexing e.g.: x[[1, 3, 8]] In [1]: x = arange(10)**2 [array([1, 3, 8])] [ ] [ ] boolean indexing e.g.: x[[false True False True True]] In [3]: x = arange(5) b = array([0, 1, 0, 1, 1], dtype=bool) y = x[b] b y [ ] [False True False True True] [1 3 4] In [2]: x = arange(10) [x%3==0] [ ] [ ] 5 of 17
6 In [5]: [x>3] [ ] In [3]: x[~(x%3==0)] Out[3]: array([1, 2, 4, 5, 7, 8]) assignment with slices In [11]: x = arange(10) x[:2] = 100 [ ] In [14]: x = arange(10) x[x%3==0] = 100 [ ] In [66]: # math on slices x = arange(10) x[x%3==0] += 100 [ ] functions (ufuncs and others) There are many, many of these. Ufuncs are the basics, and have a few extra abilities ufuncs examples: add, multiply, sin, exp, log, sqrt, bitwise_and, greater, logical_and, floor also: maximum and minimum (which should generally be used instead of Python's max and min In [107]: Out[107]: x = linspace(0, 10*pi, 10000) y = sin(x) plot(x, y) [<matplotlib.lines.line2d at 0x1886f550>] 6 of 17
7 In [108]: Out[108]: (-1, 1) z = clip(y, -.8,.8) plot(x, z); ylim(-1, 1) In [109]: Out[109]: y[y>=.8] =.5 y[y<=-.8] = -.5 plot(x, y) [<matplotlib.lines.line2d at 0x273d9650>] In [110]: Out[110]: mask = (y<.4)&(y>-.4) x[mask] += 1 plot(x, y) [<matplotlib.lines.line2d at 0x1ef4c0d0>] At this point, you know enough to make a lot of progresss. Think of the operations you want, find them in Numpy and apply them. 7 of 17
8 functions and techniques for shape manipulation (more advanced) In [28]: Out[28]: x = linspace(0, 10*pi, ) y = sin(x) +.1*sin(1000*x) plot(x, y) [<matplotlib.lines.line2d at 0x43be410>] In [26]: from IPython.core.display import Image as ipimage # just for displaying image in the notebook ipimage(filename='min01.png') Out[26]: 8 of 17
9 In [29]: m = 1000 y0 = reshape(y, (-1, m)) # y.shape = (-1, 1000) ymin = minimum.reduce(y0, axis=1) ymax = maximum.reduce(y0, axis=1) ymid = sum(y0, axis=1)/m plot(x[::m], ymin, x[::m], ymax, color='k') fill_between(x[::m], ymin, ymax, color='g') plot(x[::m], ymid, color='r') y.shape, y0.shape, ymin.shape, ymax.shape, ymid.shape ( ,) (1000, 1000) (1000,) (1000,) (1000,) In [12]: # interlude with numpy functions "sum" and "minimum" seed(8) temp0 = randint(0, 9, (2,3)) temp1 = randint(0, 9, (2,3)) temp0 temp1 "sum temp0: " "axis=0" sum(temp0, axis=0) # numpy.sum(a, axis=none, dtype=none, out=none, keepdims=false)" "axis=1" sum(temp0, axis=1) "minimum(temp0, temp1):" minimum(temp0, temp1) # numpy.minimum(x1, x2[, out]) "reduce temp0:" minimum.reduce(temp0, axis=0) minimum.reduce(temp0, axis=1) [[3 4 1] [5 8 3]] [[8 0 5] [1 3 2]] sum temp0: axis=0 [ ] axis=1 [ 8 16] minimum(temp0, temp1): [[3 0 1] [1 3 2]] reduce temp0: [3 4 1] [1 3] 9 of 17
10 In [14]: # "concatenate" # triangle wave (-2 to 3, 200 pts per period) a0 = linspace(-2, 5, 100, endpoint=false) # endpoint=false a1 = linspace(5, -2, 100, endpoint=false) b0 = concatenate((a0, a1)) plot(b0) xlim(-10, 210) ylim(-2.5, 5.5) Out[14]: (-2.5, 5.5) In [80]: Out[80]: b1 = concatenate((a0, a1)*6) plot(b1) [<matplotlib.lines.line2d at 0x59a4210>] 10 of 17
11 In [81]: # "resize" new_length = int(len(b0)*6.2) len(b0), new_length b1 = resize(b0, (new_length,)) plot(b1) Out[81]: [<matplotlib.lines.line2d at 0x59ac9d0>] In [4]: # how about "repeat"? x = arange(5) repeat(x, 4) [ ] [ ] In [33]: # newaxis "x.shape = ", x.shape "x[newaxis,:].shape = ", x[newaxis,:].shape y = repeat(x[newaxis, :], 4, axis=0) y x.shape = (5,) x[newaxis,:].shape = (1, 5) [[ ] [ ] [ ] [ ]] In [69]: # y.flat y.flat array(y.flat) # y.flat is an iterator, array(y.flat) is an ndarray <numpy.flatiter object at 0x > [ ] 11 of 17
12 In [35]: b2 = array( repeat(b0[newaxis, :], 6, axis=0).flat ) plot (b2, 'r') Out[35]: [<matplotlib.lines.line2d at 0x5099b90>] broadcasting In [38]: seed(4) x0 = randint(0, 9, (3,2)) x1 = array([5, 10]) 0 1 y = repeat(x1[newaxis,:], 3, axis=0) y 0*y [[7 5] [1 8] [7 8]] [ 5 10] [[ 5 10] [ 5 10] [ 5 10]] [[35 50] [ 5 80] [35 80]] In [85]: # broadcasting... like an automatic newaxis and repeat (without actually creating the array) y = x0*x1 y [[35 10] [ 0 60] [20 0]] 12 of 17
13 In [36]: x = linspace(-1, 1, 512) f0 = exp(-(x)**2/.05) plot(x, f0) Out[36]: [<matplotlib.lines.line2d at 0xb2a52b0>] In [37]: Out[37]: # newaxis with broadcasting! f02d = f0[newaxis,:]*f0[:,newaxis] imshow(f02d, cmap=cm.gray) <matplotlib.image.axesimage at 0x4d0f470> Numpy plays well with others... PIL 13 of 17
14 In [20]: Out[20]: from IPython.core.display import Image as ipimage # just for displaying image in the notebook ipimage(filename='lena.png') In [1]: import Image as pilimage # PIL's Image class im = pilimage.open("lena.png") im.size (512, 512) In [2]: # convert PIL image to Numpy ndarray a = array(im) a.shape type(a), a.dtype (512, 512, 3) <type 'numpy.ndarray'> uint8 14 of 17
15 In [3]: # convert to black and white using a simple sum of all colors... a = array(a, dtype=uint32) bw = sum(a, axis=2) bw.dtype, minimum.reduce(bw.flat), maximum.reduce(bw.flat) imshow(bw, cmap=cm.gray) Out[3]: uint <matplotlib.image.axesimage at 0x48ad9d0> In [47]: Out[47]: bw1 = bw.copy() bw1[bw1<150] = 1000 imshow(bw1, cmap=cm.gray) <matplotlib.image.axesimage at 0x570b4f0> In [48]: Out[48]: bw1 = roll(bw, 200, axis=1) imshow(bw1, cmap=cm.gray) <matplotlib.image.axesimage at 0x59315f0> 15 of 17
16 In [4]: x = linspace(0, 10*pi, bw.shape[0]) bw2 = bw*(1+sin(x)) imshow(bw2, cmap=cm.gray) Out[4]: <matplotlib.image.axesimage at 0x4a62b90> In [50]: Out[50]: x, y = mgrid[-1:1:512j, -1:1:512j] mask = (x**2 + y**2)<0.6**2 bw3 = bw.copy() bw3[~mask]=0 imshow(bw3, cmap=cm.gray) <matplotlib.image.axesimage at 0x6857d70> In [52]: x, y = mgrid[-2:3,-2:3] y [[ ] [ ] [ ] [ ] [ ]] [[ ] [ ] [ ] [ ] [ ]] ctypes 16 of 17
17 In [ ]: #ndarray.ctypes.data # C header C header C header C header C header C header int32 DAQmxWriteAnalogF64 (TaskHandle taskhandle, int32 numsampsperchan, bool32 autostart, float64 bool32 datalayout, float64 writearray[], int32 *sampsperchanwritten, bool32 *r #Python Python Python Python Python Python nidaq.daqmxwriteanalogf64(taskhandle, int32(numsampsperchan), int32(autostart), float64(timeout), datalayout, writearray.ctypes.data, ctypes.byref(sampsperchanwritten), None)) return sampsperchanwritten.value # that is, numpy_array.ctypes.data returns data that can be used when calling a C function with Demos: spectrum from computer's microphone In [ ]: np_data = fromstring(microphone_data, dtype=np.int16) spect = log10(abs(fft.rfft(np_data))) handwritten number classification using feedforward neural network In [38]: from IPython.core.display import Image as ipimage # just for displaying image in the notebook ipimage(filename='nn.png') Out[38]: In [ ]: X1 = np.concatenate((np.ones((m,1)), X), axis=1) z2 = np.dot(x1,theta1.t) a2 = sigmoid(z2) a2 = np.concatenate((np.ones((a2.shape[0],1)), a2), axis=1) z3 = np.dot(a2, Theta2.T); a3 = sigmoid(z3) ix = np.argmax(a3, axis=1) 17 of 17
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 informationLECTURE 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 informationLECTURE 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 informationProgramming 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 informationIntroduction 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 informationNumPy 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 informationPart 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 informationNumPy 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 informationPython 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 informationThe 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 informationThe 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 informationNumPy 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 informationPython Digital Audio Coding
Python Digital Audio Coding sebastien.boisgerault@mines-paristech.fr Learn Python 2.7 Tutorials http://docs.python.org/tutorial/ http://www.diveintopython.net http://tinyurl.com/ocw-python Scientific Computing
More informationIntroductory 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 informationProblem 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 informationIntroduction to NumPy
Introduction to NumPy Travis E. Oliphant Electrical Engineering Brigham Young University Provo, Utah http://numeric.scipy.org NumPy NumPy An N dimensional homogeneous array object Universal element by
More informationTentative NumPy Tutorial
Page 1 of 30 Tentative NumPy Tutorial Please do not hesitate to click the edit button. You will need to create a User Account first. Contents 1. Prerequisites 2. The Basics 1. An example 2. Array Creation
More informationNumPy. 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 informationIAP 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 informationPart 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 informationSciPy. 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 informationPandas 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 informationPhys 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 informationComputer Science 121. Scientific Computing Winter 2016 Chapter 3 Simple Types: Numbers, Text, Booleans
Computer Science 121 Scientific Computing Winter 2016 Chapter 3 Simple Types: Numbers, Text, Booleans 3.1 The Organization of Computer Memory Computers store information as bits : sequences of zeros and
More informationNumPy 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 informationNumPy 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 informationIntroduction 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 informationLezione 6. Installing NumPy. Contents
Lezione 6 Bioinformatica Mauro Ceccanti e Alberto Paoluzzi Dip. Informatica e Automazione Università Roma Tre Dip. Medicina Clinica Università La Sapienza Lab 01: Contents As with a lot of open-source
More informationNumpy 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 informationNumPy 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 informationEffective 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 informationnumpy-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 informationPython 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 informationARTIFICIAL 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 informationExercise: 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 informationpandas: 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 informationNumPy 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 informationWeek 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 informationShort 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 informationIntroduction to MATLAB. Computational Probability and Statistics CIS 2033 Section 003
Introduction to MATLAB Computational Probability and Statistics CIS 2033 Section 003 About MATLAB MATLAB (MATrix LABoratory) is a high level language made for: Numerical Computation (Technical computing)
More informationDerek 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 informationNumPy User Guide. Release Written by the NumPy community
NumPy User Guide Release 1.11.0 Written by the NumPy community May 29, 2016 CONTENTS 1 Setting up 3 1.1 What is NumPy?............................................. 3 1.2 Installing NumPy.............................................
More informationNumPy. 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 informationWhy 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 informationAn introduction to scientific programming with. Session 2: Numerical Python and plotting
An introduction to scientific programming with Session 2: Numerical Python and plotting So far core Python language and libraries Extra features required: fast, multidimensional arrays plotting tools libraries
More informationCh.5: Array computing and curve plotting (Part 1)
Ch.5: Array computing and curve plotting (Part 1) Joakim Sundnes 1,2 Hans Petter Langtangen 1,2 Simula Research Laboratory 1 University of Oslo, Dept. of Informatics 2 Sep 20, 2017 (Adjusted) Plan for
More informationSunpy 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 informationNumPy User Guide. Release Written by the NumPy community
NumPy User Guide Release 1.8.0 Written by the NumPy community November 10, 2013 CONTENTS 1 Introduction 3 1.1 What is NumPy?............................................. 3 1.2 Building and installing
More informationpython 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 informationData 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 informationIntroduction 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 informationPython Advance Course via Astronomy street. Sérgio Sousa (CAUP) ExoEarths Team (http://www.astro.up.pt/exoearths/)
Python Advance Course via Astronomy street Sérgio Sousa (CAUP) ExoEarths Team (http://www.astro.up.pt/exoearths/) Advance Course Outline: Python Advance Course via Astronomy street Lesson 1: Python basics
More informationImplement 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 informationParaphrase 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 informationNumerical 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 informationCME 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 informationPython Compact. 1 Python Compact. 2 What do we cover in this introduction lecture? February 7, What is also interesting to know?
Python Compact February 7, 2018 1 Python Compact 1.0.1 Claus Führer, Lund University Short introduction to Python for participants of the course ** Numerical Methods - Review and Training ** Volvo Cars,
More informationPython (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 informationLecture 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 informationHandling 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 informationParakeet. A Runtime Compiler for Numerical Python
Parakeet A Runtime Compiler for Numerical Python Alex Rubinsteyn @ PyData Boston 2013 What s Parakeet? A runtime compiler for numerical Python Runtime Compiler When you call a function, Parakeet bakes
More informationNumPy. 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 informationLogistic Regression with a Neural Network mindset
Logistic Regression with a Neural Network mindset Welcome to your first (required) programming assignment! You will build a logistic regression classifier to recognize cats. This assignment will step you
More informationMATPLOTLIB. 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 informationIntroduction 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 informationMS6021 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 informationPython 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 informationScientific 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 informationIntelligente 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 informationNumPy User Guide. Release Written by the NumPy community
NumPy User Guide Release 1.14.0 Written by the NumPy community January 08, 2018 CONTENTS 1 Setting up 3 2 Quickstart tutorial 5 3 NumPy basics 29 4 Miscellaneous 73 5 NumPy for Matlab users 79 6 Building
More informationScientific 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 informationIntroduction to MATLAB. Simon O Keefe Non-Standard Computation Group
Introduction to MATLAB Simon O Keefe Non-Standard Computation Group sok@cs.york.ac.uk Content n An introduction to MATLAB n The MATLAB interfaces n Variables, vectors and matrices n Using operators n Using
More informationENGR (Socolofsky) Week 07 Python scripts
ENGR 102-213 (Socolofsky) Week 07 Python scripts A couple programming examples for this week are embedded in the lecture notes for Week 7. We repeat these here as brief examples of typical array-like operations
More informationINTRODUCTION 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 informationIntroduction 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 informationPHY224 Practical Physics I Python Review Lecture 1 Sept , 2013
PHY224 Practical Physics I Python Review Lecture 1 Sept. 16-17, 2013 Summary Python objects Lists and arrays Input (raw_input) and output Control Structures: iterations References M H. Goldwasser, D. Letscher:
More informationPython 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 informationIntroduction 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 informationWhat is Data Science?
What is Data Science? Data science ~ computer science + mathematics/statistics + visualization Outline of a data science project Harvesting Cleaning Analyzing Visualizing Publishing Actively used Python
More informationDSC 201: Data Analysis & Visualization
DSC 201: Data Analysis & Visualization Classes & Arrays Dr. David Koop Sets Sets are like dictionaries but without any values: s = {'MA', 'RI', 'CT', 'NH'}; t = {'MA', 'NY', 'NH'} {} is an empty dictionary,
More informationChapter 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 informationFile Input/Output in Python. October 9, 2017
File Input/Output in Python October 9, 2017 Moving beyond simple analysis Use real data Most of you will have datasets that you want to do some analysis with (from simple statistics on few hundred sample
More informationPython An Introduction
Python An Introduction Calle Lejdfors and Lennart Ohlsson calle.lejdfors@cs.lth.se Python An Introduction p. 1 Overview Basic Python Numpy Python An Introduction p. 2 What is Python? Python plays a key
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.
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 informationHANDS 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 informationPyPlot. The plotting library must be imported, and we will assume in these examples an import statement similar to those for numpy and math as
Geog 271 Geographic Data Analysis Fall 2015 PyPlot Graphicscanbeproducedin Pythonviaavarietyofpackages. We willuseapythonplotting package that is part of MatPlotLib, for which documentation can be found
More informationChapter 2. Python Programming for Physicists. Soon-Hyung Yook. March 31, Soon-Hyung Yook Chapter 2 March 31, / 52
Chapter 2 Python Programming for Physicists Soon-Hyung Yook March 31, 2017 Soon-Hyung Yook Chapter 2 March 31, 2017 1 / 52 Table of Contents I 1 Getting Started 2 Basic Programming Variables and Assignments
More informationA Python wrapper for NASA's Radar Software Library
A Python wrapper for NASA's Radar Software Library Eric Bruning TTU Department of Geosciences Atmospheric Science Group 2011 AMS Annual Meeting, Seattle Python Symposium Paper 4.4 27 January 2011, 4:15
More informationLab: Numerics with Numpy. Day 1. Copyright Oliver Serang, 2018 University of Montana Department of Computer Science
1 Lab: Numerics with Numpy Copyright Oliver Serang, 2018 University of Montana Department of Computer Science Day 1 numpy is one of the most popular numeric libraries in the world. Using the numpy.array
More informationResearch Computing with Python, Lecture 1
Research Computing with Python, Lecture 1 Ramses van Zon SciNet HPC Consortium November 4, 2014 Ramses van Zon (SciNet HPC Consortium)Research Computing with Python, Lecture 1 November 4, 2014 1 / 35 Introduction
More informationDATA STRUCTURE AND ALGORITHM USING PYTHON
DATA STRUCTURE AND ALGORITHM USING PYTHON Common Use Python Module II Peter Lo Pandas Data Structures and Data Analysis tools 2 What is Pandas? Pandas is an open-source Python library providing highperformance,
More informationPython 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 informationA. Python Crash Course
A. Python Crash Course Agenda A.1 Installing Python & Co A.2 Basics A.3 Data Types A.4 Conditions A.5 Loops A.6 Functions A.7 I/O A.8 OLS with Python 2 A.1 Installing Python & Co You can download and install
More informationThe 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 informationHW0 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 informationMatplotlib 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 informationIntroduction to Scientific Python, CME 193 Jan. 9, web.stanford.edu/~ermartin/teaching/cme193-winter15
1 LECTURE 1: INTRO Introduction to Scientific Python, CME 193 Jan. 9, 2014 web.stanford.edu/~ermartin/teaching/cme193-winter15 Eileen Martin Some slides are from Sven Schmit s Fall 14 slides 2 Course Details
More informationLab 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(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 informationDSC 201: Data Analysis & Visualization
DSC 201: Data Analysis & Visualization Data Frames Dr. David Koop pandas Contains high-level data structures and manipulation tools designed to make data analysis fast and easy in Python Built on top of
More information