Random Walks & Cellular Automata

Size: px
Start display at page:

Download "Random Walks & Cellular Automata"

Transcription

1 Random Walks & Cellular Automata 1 Particle Movements basic version of the simulation vectorized implementation 2 Cellular Automata pictures of matrices an animation of matrix plots the game of life of John Conway 3 Vectorizing the Game of Life performance issues vectorizing the neighbor count vectorizing the rules MCS 507 Lecture 29 Mathematical, Statistical and Scientific Software Jan Verschelde, 1 November 2013 Scientific Software (MCS 507 L-29) random walks and cellular automata 1 November / 41

2 Random Walks & Cellular Automata 1 Particle Movements basic version of the simulation vectorized implementation 2 Cellular Automata pictures of matrices an animation of matrix plots the game of life of John Conway 3 Vectorizing the Game of Life performance issues vectorizing the neighbor count vectorizing the rules Scientific Software (MCS 507 L-29) random walks and cellular automata 1 November / 41

3 particle movements Scientific Software (MCS 507 L-29) random walks and cellular automata 1 November / 41

4 designing the simulation All particles originate at (0, 0). For every particle, for every time step do: 1 generate a random integer d {1, 2, 3, 4}, 2 move according to the value of d: 1 if d = 1: move particle north 2 if d = 2: move particle south 3 if d = 3: move particle east 4 if d = 4: move particle west Scientific Software (MCS 507 L-29) random walks and cellular automata 1 November / 41

5 the script walk.py import numpy as np import random from scitools.std import plot def particles(npa, nst, pls): Shows random particle movement with npa : number of particles, nst : number of time steps, pls : how many steps for next plot. Scientific Software (MCS 507 L-29) random walks and cellular automata 1 November / 41

6 the script continued xpa = np.zeros(npa) ypa = np.zeros(npa) xymax = 3*np.sqrt(nst) xymin = -xymax for step in range(nst): for i in range(npa): die = random.randint(1, 4) if die == 1: ypa[i] += 1 # north elif die == 2: ypa[i] -= 1 # south elif die == 3: xpa[i] += 1 # east elif die == 4: xpa[i] -= 1 # west Scientific Software (MCS 507 L-29) random walks and cellular automata 1 November / 41

7 plotting and the main function if((step+1) % pls == 0): plot(xpa, ypa, bo, \ axis=[xymin, xymax, xymin, xymax], \ title= %d particles after %d steps \ % (npa, step+1)) def main(): Fixes the seed for the random numbers and starts the particle simulation. random.seed(10) particles(3000, 4000, 20) will run a simulation of 3000 particles over 4000 stages plotted every 20 time steps. Scientific Software (MCS 507 L-29) random walks and cellular automata 1 November / 41

8 Random Walks & Cellular Automata 1 Particle Movements basic version of the simulation vectorized implementation 2 Cellular Automata pictures of matrices an animation of matrix plots the game of life of John Conway 3 Vectorizing the Game of Life performance issues vectorizing the neighbor count vectorizing the rules Scientific Software (MCS 507 L-29) random walks and cellular automata 1 November / 41

9 vectorization Vectorization: replace the Python for loops by NumPy operations on arrays. To speed up the simulation: 1 generate all random directions at once, 2 use where to update coordinates. The built-in function where has the syntax numpy.where(condition, [x, y]) and returns elements either from x or y (optional) depending on condition. Scientific Software (MCS 507 L-29) random walks and cellular automata 1 November / 41

10 generating all moves def particles(npa, nst, pls): Shows random particle movement with npa : number of particles, nst : number of time steps, pls : how many steps for next plot. xpa = np.zeros(npa) ypa = np.zeros(npa) xymax = 3*np.sqrt(nst) xymin = -xymax moves = np.random.random_integers(1, 4, nst*npa) moves.shape = (nst, npa) Scientific Software (MCS 507 L-29) random walks and cellular automata 1 November / 41

11 script walkvector.py continued for step in range(nst): this_move = moves[step, :] ypa += np.where(this_move == 1, 1, 0) ypa -= np.where(this_move == 2, 1, 0) xpa += np.where(this_move == 3, 1, 0) xpa -= np.where(this_move == 4, 1, 0) if((step+1) % pls == 0): plot(xpa, ypa, bo, \ axis=[xymin, xymax, xymin, xymax], \ title= %d particles after %d steps \ % (npa, step+1)) Scientific Software (MCS 507 L-29) random walks and cellular automata 1 November / 41

12 Random Walks & Cellular Automata 1 Particle Movements basic version of the simulation vectorized implementation 2 Cellular Automata pictures of matrices an animation of matrix plots the game of life of John Conway 3 Vectorizing the Game of Life performance issues vectorizing the neighbor count vectorizing the rules Scientific Software (MCS 507 L-29) random walks and cellular automata 1 November / 41

13 visualizing a matrix Scientific Software (MCS 507 L-29) random walks and cellular automata 1 November / 41

14 running the code $ python spy_plot.py [[ , 0 0 0] [ , 0 1 1] [ , 0 0 0]..., [ , 0 0 0] [ , 0 1 0] [ , 0 0 0]] number of nonzeros : 964 quit? (y/n) Scientific Software (MCS 507 L-29) random walks and cellular automata 1 November / 41

15 a plot of a matrix Every nonzero element of the matrix is represented by a red disk in a plot. Extract rows and columns of nonzeroes of A: 1 from scipy import sparse 2 convert the matrix A into a sparse matrix, in coordinate format: S = sparse.coo_matrix(a) 3 x = S.row; y = S.col give in x and y the rows and columns of nonzeroes. Scientific Software (MCS 507 L-29) random walks and cellular automata 1 November / 41

16 the script spy_plot.py import numpy as np from scipy import sparse from scitools.std import plot R = 0.1 # ratio of nonzeroes N = 100 # dimension of the matrix A = np.random.rand(n, N) A = np.matrix(a < R, int) print A S = sparse.coo_matrix(a) print number of nonzeros :, S.nnz plot(s.row, S.col, ro, axis=[-1, N, -1, N]) raw_input( press any key to quit ) Scientific Software (MCS 507 L-29) random walks and cellular automata 1 November / 41

17 Random Walks & Cellular Automata 1 Particle Movements basic version of the simulation vectorized implementation 2 Cellular Automata pictures of matrices an animation of matrix plots the game of life of John Conway 3 Vectorizing the Game of Life performance issues vectorizing the neighbor count vectorizing the rules Scientific Software (MCS 507 L-29) random walks and cellular automata 1 November / 41

18 a movie of matrices We generate a sequence of random matrices of the same dimension n = 100 and ratio of nonzeroes r = 0.1. For each generated random matrix: 1 compute rows and columns of nonzeroes, 2 plot rows and columns as red disks. Scientific Software (MCS 507 L-29) random walks and cellular automata 1 November / 41

19 spy_plot_movie.py import numpy as np from scitools.std import plot from scipy import sparse R = 0.1 # ratio of nonzeroes N = 100 # dimension of the matrix for i in range(n): A = np.random.rand(n, N) A = np.matrix(a < R, int) S = sparse.coo_matrix(a) plot(s.row, S.col, ro, axis=[-1, N, -1, N], \ title= matrix %d has %d nonzeroes % (i, S.nnz)) Scientific Software (MCS 507 L-29) random walks and cellular automata 1 November / 41

20 Random Walks & Cellular Automata 1 Particle Movements basic version of the simulation vectorized implementation 2 Cellular Automata pictures of matrices an animation of matrix plots the game of life of John Conway 3 Vectorizing the Game of Life performance issues vectorizing the neighbor count vectorizing the rules Scientific Software (MCS 507 L-29) random walks and cellular automata 1 November / 41

21 visualizing living cells Scientific Software (MCS 507 L-29) random walks and cellular automata 1 November / 41

22 simulating cellular growth The game of life is a discovery of John Conway. Consider a rectangular grid of cells with rules: 1 An empty cell is born when it has 3 neighbors. 2 A living cell can either die or survive, as follows: 1 die by loneliness, if the cell has one or no neighbors; 2 die by overpopulation, if the cell has 4 neighbors; 3 survive, if the cell has two or three neighbors. Scientific Software (MCS 507 L-29) random walks and cellular automata 1 November / 41

23 design of the code Three ingredients: 1 The rectangular grid is represented by a NumPy matrix A of integers: Ai,j {0, 1}, Ai,j = 0: cell (i, j) is dead, Ai,j = 1: cell (i, j) is alive. 2 We update the matrix applying the rules, running over all pairs of indices (i, j). 3 We use plot of scitools.std to the rows and columns of the nonzero entries. Scientific Software (MCS 507 L-29) random walks and cellular automata 1 November / 41

24 the main function def main(): Generates a random matrix and applies the rules for Conway s game of life. ratio = 0.2 # ratio of nonzeroes dim = input( give the dimension : ) alive = np.random.rand(dim, dim) alive = np.matrix(alive < ratio, int) for i in xrange(10*dim): spm = sparse.coo_matrix(alive) plot(spm.row, spm.col, r., \ axis=[-1, dim, -1, dim], \ title= stage %d % i) alive = update(alive) Scientific Software (MCS 507 L-29) random walks and cellular automata 1 November / 41

25 applying the rules def update(alive): Applies the rules of Conway s game of life. result = np.zeros(alive.shape, int) for i in range(0, alive.shape[0]): for j in range(0, alive.shape[1]): nbn = neighbors(alive, i, j) if alive[i, j] == 1: if((nbn < 2) or (nbn > 3)): result[i, j] = 0 else: result[i, j] = 1 else: if(nbn == 3): result[i, j] = 1 return result Scientific Software (MCS 507 L-29) random walks and cellular automata 1 November / 41

26 counting live neighbors def neighbors(alive, i, j): Returns the number of cells alive next to alive[i, j]. cnt = 0 if i > 0: if alive[i-1, j]: cnt = cnt + 1 if(j > 0): if alive[i-1, j-1]: cnt = cnt + 1 if(j < alive.shape[1]-1): if alive[i-1, j+1]: cnt = cnt + 1 Scientific Software (MCS 507 L-29) random walks and cellular automata 1 November / 41

27 counting live neighbors continued if(i < alive.shape[0]-1): if alive[i+1, j]: cnt = cnt + 1 if(j > 0): if alive[i+1, j-1]: cnt = cnt + 1 if(j < alive.shape[1]-1): if alive[i+1, j+1]: cnt = cnt + 1 if(j > 0): if alive[i, j-1]: cnt = cnt + 1 if(j < alive.shape[1]-1): if alive[i, j+1]: cnt = cnt + 1 return cnt Scientific Software (MCS 507 L-29) random walks and cellular automata 1 November / 41

28 Random Walks & Cellular Automata 1 Particle Movements basic version of the simulation vectorized implementation 2 Cellular Automata pictures of matrices an animation of matrix plots the game of life of John Conway 3 Vectorizing the Game of Life performance issues vectorizing the neighbor count vectorizing the rules Scientific Software (MCS 507 L-29) random walks and cellular automata 1 November / 41

29 performance issues The straightforward code does not work well on a MacBook when the dimension gets at n = 300. Reasons for the problems with performance: Traversals through the matrix with double for loops in Python: incrementing loop counters is expensive. The loop counts i and j are Python objects. In counting the neighbors we access not only the (i, j)-th data element, but also (i 1, j), (i + 1, j), (i, j 1), and (i, j + 1). In the row or column oriented storing of the matrix, getting access to respectively (i 1, j),(i + 1, j) or (i, j 1),(i, j + 1) means accessing n elements before or after the (i, j)-th element. Vectorization reorganizes the counting of the live neighbors and the application of the rules. Scientific Software (MCS 507 L-29) random walks and cellular automata 1 November / 41

30 Random Walks & Cellular Automata 1 Particle Movements basic version of the simulation vectorized implementation 2 Cellular Automata pictures of matrices an animation of matrix plots the game of life of John Conway 3 Vectorizing the Game of Life performance issues vectorizing the neighbor count vectorizing the rules Scientific Software (MCS 507 L-29) random walks and cellular automata 1 November / 41

31 vectorizing the neighbor count For every cell (i, j) in the matrix we need to count the number of neighbors that are alive. We need to avoid to access at the same time the left, right, upper and lower neighbors because of the way matrices are stored. Idea: to count the right neighbors of live cells add to the matrix the same matrix shifted one column. Scientific Software (MCS 507 L-29) random walks and cellular automata 1 November / 41

32 counting the right live neighbors >>> import numpy as np >>> A = np.random.rand(5,5) >>> A = np.matrix(a < 0.3,int); A matrix([[1, 1, 1, 1, 1], [1, 1, 0, 0, 1], [0, 0, 0, 0, 0], [0, 0, 1, 1, 0], [0, 0, 0, 0, 0]]) >>> B = np.copy(a[:,+1:]) >>> B array([[1, 1, 1, 1], [1, 0, 0, 1], [0, 0, 0, 0], [0, 1, 1, 0], [0, 0, 0, 0]]) >>> A[:,:-1] = np.copy(a[:,:-1]) + B >>> A matrix([[2, 2, 2, 2, 1], [2, 1, 0, 1, 1], [0, 0, 0, 0, 0], [0, 1, 2, 1, 0], [0, 0, 0, 0, 0]]) Scientific Software (MCS 507 L-29) random walks and cellular automata 1 November / 41

33 the script game_neighbors.py def neighbor_count_matrix(alive): Returns a matrix counting the number of live neighbors. acopy = np.copy(alive) result = np.copy(alive) left = np.copy(result[:, :-1]) # omit last column right = np.copy(result[:, +1:]) # omit first column result[:, +1:] = np.copy(result[:, +1:]) + left result[:, :-1] = np.copy(result[:, :-1]) + right upper = np.copy(result[:-1, :]) # omit last row lower = np.copy(result[+1:, :]) # omit last column result[+1:, :] = np.copy(result[+1:, :]) + upper result[:-1, :] = np.copy(result[:-1, :]) + lower result = result - acopy return result Scientific Software (MCS 507 L-29) random walks and cellular automata 1 November / 41

34 the main test def main(): Test on neighbor count. dim = 8 ratio = 0.2 alive = np.random.rand(dim, dim) alive = np.matrix(alive < ratio, int) count = neighbor_count_matrix(alive) print cells alive\n, alive print vectorized neighbor count\n, count orgcnt = neighbor_count(alive) print original neighbor count\n, orgcnt print equality check : print np.equal(count, orgcnt) print sum(sum(np.equal(count, orgcnt))) Scientific Software (MCS 507 L-29) random walks and cellular automata 1 November / 41

35 Random Walks & Cellular Automata 1 Particle Movements basic version of the simulation vectorized implementation 2 Cellular Automata pictures of matrices an animation of matrix plots the game of life of John Conway 3 Vectorizing the Game of Life performance issues vectorizing the neighbor count vectorizing the rules Scientific Software (MCS 507 L-29) random walks and cellular automata 1 November / 41

36 recall the where method Converting a 0/1 matrix into a Boolean matrix: >>> A = np.random.rand(4,4) >>> A = np.matrix(a < 0.5, int) >>> A matrix([[0, 1, 1, 1], [0, 1, 0, 1], [1, 1, 1, 0], [0, 0, 1, 1]]) >>> B = np.where(a > 0, True, False) >>> B matrix([[false, True, True, True], [False, True, False, True], [ True, True, True, False], [False, False, True, True]], dtype=bool) Scientific Software (MCS 507 L-29) random walks and cellular automata 1 November / 41

37 die of loneliness >>> import numpy as np >>> A = np.random.rand(5,5) >>> A = np.matrix(a < 0.4,int) >>> A matrix([[0, 0, 0, 0, 0], [1, 1, 0, 0, 1], [1, 0, 0, 1, 0], [0, 0, 0, 1, 0], [0, 0, 0, 0, 1]]) >>> from game_neighbors import neighbor_count_matrix >>> B = neighbor_count_matrix(a) >>> B array([[2, 2, 1, 1, 1], [2, 2, 2, 2, 1], [2, 3, 3, 2, 3], [1, 1, 2, 2, 3], [0, 0, 1, 2, 1]]) >>> lonely = np.where(b < 2,0,A); lonely array([[0, 0, 0, 0, 0], [1, 1, 0, 0, 0], [1, 0, 0, 1, 0], [0, 0, 0, 1, 0], [0, 0, 0, 0, 0]]) Scientific Software (MCS 507 L-29) random walks and cellular automata 1 November / 41

38 the script game_rules.py import numpy as np from game_neighbors import neighbor_count_matrix def update_matrix(alive, count): The vectorized version of update. starve = np.where(count > 3, 0, alive) lonely = np.where(count < 2, 0, starve) return np.where(count == 3, 1, lonely) To test, we compare the update methods. Scientific Software (MCS 507 L-29) random walks and cellular automata 1 November / 41

39 testing the vectorized rules def main(): Test on the rules, comparing the original with the vectorized version of the rules. dim = 10 ratio = 0.3 alive = np.random.rand(dim, dim) alive = np.matrix(alive < ratio, int) count = neighbor_count_matrix(alive) first_update = update(alive, count) print live cells :\n, alive print apply original rules :\n, first_update second_update = update_matrix(alive, count) print apply matrix rules :\n, second_update print equality check : print np.equal(first_update, second_update) print sum(sum(np.equal(first_update, second_update))) Scientific Software (MCS 507 L-29) random walks and cellular automata 1 November / 41

40 the vectorized game The script game_vector.py has a different update: import numpy as np from scitools.std import plot from scipy import sparse from game_neighbors import neighbor_count_matrix from game_rules import update_matrix def update(alive): Applies the rules of Conway s game of life. counts = neighbor_count_matrix(alive) return update_matrix(alive, counts) Scientific Software (MCS 507 L-29) random walks and cellular automata 1 November / 41

41 Summary + Exercises Random walks and cellular automata simulate and model complicated dynamical systems. Vectorization is often critical for good performance. 1 Use the canvas of Tkinter for a GUI to make the game of life. Allow the user to define configurations of living cells via mouse clicks on the canvas. 2 Apply vectorization to your GUI. Compare the performance of your versions with and without factorization. Compare the performance of your vectorized GUI with the version that uses scitools.std. Homework Five due Friday 15 November at 9AM: exercises 2 and 3 of lecture 21; exercise 1 of lecture 22; exercise 2 of lecture 23; exercises 1 and 2 of lecture 24; exercises 1 and 2 of lecture 25; exercises 1 and 3 of lecture 26. Scientific Software (MCS 507 L-29) random walks and cellular automata 1 November / 41

Random Walks & Cellular Automata

Random Walks & Cellular Automata Random Walks & Cellular Automata 1 Particle Movements basic version of the simulation vectorized implementation 2 Cellular Automata pictures of matrices an animation of matrix plots the game of life of

More information

Running Cython and Vectorization

Running Cython and Vectorization Running Cython and Vectorization 1 Getting Started with Cython overview hello world with Cython 2 Numerical Integration experimental setup adding type declarations cdef functions & calling external functions

More information

Running Cython and Vectorization

Running Cython and Vectorization Running Cython and Vectorization 1 Getting Started with Cython overview hello world with Cython 2 Numerical Integration experimental setup adding type declarations cdef functions & calling external functions

More information

Running Cython. overview hello world with Cython. experimental setup adding type declarations cdef functions & calling external functions

Running Cython. overview hello world with Cython. experimental setup adding type declarations cdef functions & calling external functions Running Cython 1 Getting Started with Cython overview hello world with Cython 2 Numerical Integration experimental setup adding type declarations cdef functions & calling external functions 3 Using Cython

More information

Branching and Enumeration

Branching and Enumeration Branching and Enumeration 1 Booleans and Branching computing logical expressions computing truth tables with Sage if, else, and elif 2 Timing Python Code try-except costs more than if-else 3 Recursive

More information

making connections general transit feed specification stop names and stop times storing the connections in a dictionary

making connections general transit feed specification stop names and stop times storing the connections in a dictionary making connections 1 CTA Tables general transit feed specification stop names and stop times storing the connections in a dictionary 2 CTA Schedules finding connections between stops sparse matrices in

More information

Web Interfaces. the web server Apache processing forms with Python scripts Python code to write HTML

Web Interfaces. the web server Apache processing forms with Python scripts Python code to write HTML Web Interfaces 1 Python Scripts in Browsers the web server Apache processing forms with Python scripts Python code to write HTML 2 Web Interfaces for the Determinant dynamic interactive forms passing data

More information

Graph Adjacency Matrix Automata Joshua Abbott, Phyllis Z. Chinn, Tyler Evans, Allen J. Stewart Humboldt State University, Arcata, California

Graph Adjacency Matrix Automata Joshua Abbott, Phyllis Z. Chinn, Tyler Evans, Allen J. Stewart Humboldt State University, Arcata, California Graph Adjacency Matrix Automata Joshua Abbott, Phyllis Z. Chinn, Tyler Evans, Allen J. Stewart Humboldt State University, Arcata, California Abstract We define a graph adjacency matrix automaton (GAMA)

More information

June 10, 2014 Scientific computing in practice Aalto University

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

More information

Introduction To Python

Introduction To Python Introduction To Python Week 7: Program Dev: Conway's Game of Life Dr. Jim Lupo Asst Dir Computational Enablement LSU Center for Computation & Technology 9 Jul 2015, Page 1 of 33 Overview Look at a helpful

More information

User Interfaces. MCS 507 Lecture 11 Mathematical, Statistical and Scientific Software Jan Verschelde, 16 September Command Line Interfaces

User Interfaces. MCS 507 Lecture 11 Mathematical, Statistical and Scientific Software Jan Verschelde, 16 September Command Line Interfaces User 1 2 MCS 507 Lecture 11 Mathematical, Statistical and Scientific Software Jan Verschelde, 16 September 2011 User 1 2 command line interfaces Many programs run without dialogue with user, as $ executable

More information

CELLULAR AUTOMATA IN MATHEMATICAL MODELING JOSH KANTOR. 1. History

CELLULAR AUTOMATA IN MATHEMATICAL MODELING JOSH KANTOR. 1. History CELLULAR AUTOMATA IN MATHEMATICAL MODELING JOSH KANTOR 1. History Cellular automata were initially conceived of in 1948 by John von Neumann who was searching for ways of modeling evolution. He was trying

More information

2D Arrays. Lecture 25

2D Arrays. Lecture 25 2D Arrays Lecture 25 Apply to be a COMP110 UTA Applications are open at http://comp110.com/become-a-uta/ Due December 6 th at 11:59pm LDOC Hiring committee is made of 8 elected UTAs 2D Arrays 0 1 2 Easy

More information

Graphical User Interfaces

Graphical User Interfaces Graphical User Interfaces 1 User Interfaces GUIs in Python with Tkinter object oriented GUI programming 2 Mixing Colors specification of the GUI the widget Scale 3 Simulating a Bouncing Ball layout of

More information

Fall CSE 633 Parallel Algorithms. Cellular Automata. Nils Wisiol 11/13/12

Fall CSE 633 Parallel Algorithms. Cellular Automata. Nils Wisiol 11/13/12 Fall 2012 CSE 633 Parallel Algorithms Cellular Automata Nils Wisiol 11/13/12 Simple Automaton: Conway s Game of Life Simple Automaton: Conway s Game of Life John H. Conway Simple Automaton: Conway s Game

More information

Graphical User Interfaces

Graphical User Interfaces to visualize Graphical User Interfaces 1 2 to visualize MCS 507 Lecture 12 Mathematical, Statistical and Scientific Software Jan Verschelde, 19 September 2011 Graphical User Interfaces to visualize 1 2

More information

Assignment 5. INF109 Dataprogrammering for naturvitskap

Assignment 5. INF109 Dataprogrammering for naturvitskap Assignment 5 INF109 Dataprogrammering for naturvitskap This is the fifth of seven assignments. You can get a total of 15 points for this task. Friday, 8. April, 23.59. Submit the report as a single.py

More information

Multithreaded Servers

Multithreaded Servers Multithreaded Servers 1 Serving Multiple Clients avoid to block clients with waiting using sockets and threads 2 Waiting for Data from 3 Clients running a simple multithreaded server code for client and

More information

Cellular Automata Language (CAL) Language Reference Manual

Cellular Automata Language (CAL) Language Reference Manual Cellular Automata Language (CAL) Language Reference Manual Calvin Hu, Nathan Keane, Eugene Kim {ch2880, nak2126, esk2152@columbia.edu Columbia University COMS 4115: Programming Languages and Translators

More information

UNIT 9C Randomness in Computation: Cellular Automata Principles of Computing, Carnegie Mellon University

UNIT 9C Randomness in Computation: Cellular Automata Principles of Computing, Carnegie Mellon University UNIT 9C Randomness in Computation: Cellular Automata 1 Exam locations: Announcements 2:30 Exam: Sections A, B, C, D, E go to Rashid (GHC 4401) Sections F, G go to PH 125C. 3:30 Exam: All sections go to

More information

Lists and Loops. defining lists lists as queues and stacks inserting and removing membership and ordering lists

Lists and Loops. defining lists lists as queues and stacks inserting and removing membership and ordering lists Lists and Loops 1 Lists in Python defining lists lists as queues and stacks inserting and removing membership and ordering lists 2 Loops in Python for and while loops the composite trapezoidal rule MCS

More information

A Slice of Life

A Slice of Life A Slice of Life 02-201 More on Slices Last Time: append() and copy() Operations s := make([]int, 10)! s = append(s, 5)! 0! 0! 0! 0! 0! 0! 0! 0! 0! 0! 5! 0! 1! 2! 3! 4! 5! 6! 7! 8! 9! 10! s! c := make([]int,

More information

User Interfaces. getting arguments of the command line a command line interface to store points fitting points with polyfit of numpy

User Interfaces. getting arguments of the command line a command line interface to store points fitting points with polyfit of numpy User Interfaces 1 Command Line Interfaces getting arguments of the command line a command line interface to store points fitting points with polyfit of numpy 2 Encapsulation by Object Oriented Programming

More information

Problem 3. (12 points):

Problem 3. (12 points): Problem 3. (12 points): This problem tests your understanding of basic cache operations. Harry Q. Bovik has written the mother of all game-of-life programs. The Game-of-life is a computer game that was

More information

Conway s Game of Life Wang An Aloysius & Koh Shang Hui

Conway s Game of Life Wang An Aloysius & Koh Shang Hui Wang An Aloysius & Koh Shang Hui Winner of Foo Kean Pew Memorial Prize and Gold Award Singapore Mathematics Project Festival 2014 Abstract Conway s Game of Life is a cellular automaton devised by the British

More information

CSCI-1200 Data Structures Spring 2017 Lecture 15 Problem Solving Techniques, Continued

CSCI-1200 Data Structures Spring 2017 Lecture 15 Problem Solving Techniques, Continued CSCI-1200 Data Structures Spring 2017 Lecture 15 Problem Solving Techniques, Continued Review of Lecture 14 General Problem Solving Techniques: 1. Generating and Evaluating Ideas 2. Mapping Ideas into

More information

implementing the breadth-first search algorithm implementing the depth-first search algorithm

implementing the breadth-first search algorithm implementing the depth-first search algorithm Graph Traversals 1 Graph Traversals representing graphs adjacency matrices and adjacency lists 2 Implementing the Breadth-First and Depth-First Search Algorithms implementing the breadth-first search algorithm

More information

HW3: CS 110X C Domain Information. Final Version: 1/29/2014

HW3: CS 110X C Domain Information. Final Version: 1/29/2014 HW3: CS 110X C 2014 Note: This homework (and all remaining homework assignments) is a partner homework and must be completed by each partner pair. When you complete this assignment, you must not share

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

Example 1: Give the coordinates of the points on the graph.

Example 1: Give the coordinates of the points on the graph. Ordered Pairs Often, to get an idea of the behavior of an equation, we will make a picture that represents the solutions to the equation. A graph gives us that picture. The rectangular coordinate plane,

More information

Root Finding Methods. sympy and Sage. MCS 507 Lecture 13 Mathematical, Statistical and Scientific Software Jan Verschelde, 21 September 2011

Root Finding Methods. sympy and Sage. MCS 507 Lecture 13 Mathematical, Statistical and Scientific Software Jan Verschelde, 21 September 2011 wrap Root Finding Methods 1 2 wrap MCS 507 Lecture 13 Mathematical, Statistical and Scientific Software Jan Verschelde, 21 September 2011 Root Finding Methods 1 wrap 2 wrap wrap octave-3.4.0:1> p = [1,0,2,-1]

More information

7/27/2015. UNIT 10A Discrete Simulation. Last Time. Waking Up. How to generate pseudo-random numbers. Using randomness in interesting applications

7/27/2015. UNIT 10A Discrete Simulation. Last Time. Waking Up. How to generate pseudo-random numbers. Using randomness in interesting applications 15110 Principles of Computing, Carnegie Mellon University UNIT 10A Discrete Simulation 1 Last Time How to generate pseudo-random numbers Using randomness in interesting applications Monte Carlo simulations:

More information

processing data with a database

processing data with a database processing data with a database 1 MySQL and MySQLdb MySQL: an open source database running MySQL for database creation MySQLdb: an interface to MySQL for Python 2 CTA Tables in MySQL files in GTFS feed

More information

lambda forms map(), reduce(), filter(), eval(), and apply() estimating π with list comprehensions

lambda forms map(), reduce(), filter(), eval(), and apply() estimating π with list comprehensions Outline 1 Guessing Secrets functions returning functions oracles and trapdoor functions 2 anonymous functions lambda forms map(), reduce(), filter(), eval(), and apply() estimating π with list comprehensions

More information

Part 1 (80 points) Multiple Choice Questions (20 questions * 4 points per question = 80 points)

Part 1 (80 points) Multiple Choice Questions (20 questions * 4 points per question = 80 points) EECS 183 Fall 2013 Exam 1 Part 1 (80 points) Closed Book Closed Notes Closed Electronic Devices Closed Neighbor Turn off Your Cell Phones We will confiscate all electronic devices that we see including

More information

Graphs. directed and undirected graphs weighted graphs adjacency matrices. abstract data type adjacency list adjacency matrix

Graphs. directed and undirected graphs weighted graphs adjacency matrices. abstract data type adjacency list adjacency matrix Graphs 1 Graphs directed and undirected graphs weighted graphs adjacency matrices 2 Graph Representations abstract data type adjacency list adjacency matrix 3 Graph Implementations adjacency matrix adjacency

More information

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

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

More information

callback, iterators, and generators

callback, iterators, and generators callback, iterators, and generators 1 Adding a Callback Function a function for Newton s method a function of the user to process results 2 A Newton Iterator defining a counter class refactoring the Newton

More information

Programming Project: Game of Life

Programming Project: Game of Life Programming Project: Game of Life Collaboration Solo: All work must be your own with optional help from UofA section leaders The Game of Life was invented by John Conway to simulate the birth and death

More information

Erlang: concurrent programming. Johan Montelius. October 2, 2016

Erlang: concurrent programming. Johan Montelius. October 2, 2016 Introduction Erlang: concurrent programming Johan Montelius October 2, 2016 In this assignment you should implement the game of life, a very simple simulation with surprising results. You will implement

More information

CmpSci 187: Programming with Data Structures Spring 2015

CmpSci 187: Programming with Data Structures Spring 2015 CmpSci 187: Programming with Data Structures Spring 2015 Lecture #9 John Ridgway February 26, 2015 1 Recursive Definitions, Algorithms, and Programs Recursion in General In mathematics and computer science

More information

Numerical Integration

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

More information

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

Random Numbers Random Walk

Random Numbers Random Walk Random Numbers Random Walk Computational Physics Random Numbers Random Walk Outline Random Systems Random Numbers Monte Carlo Integration Example Random Walk Exercise 7 Introduction Random Systems Deterministic

More information

MORE ARRAYS: THE GAME OF LIFE CITS1001

MORE ARRAYS: THE GAME OF LIFE CITS1001 MORE ARRAYS: THE GAME OF LIFE CITS1001 2 Scope of this lecture The Game of Life Implementation Performance Issues References: http://www.bitstorm.org/gameoflife/ (and hundreds of other websites) 3 Game

More information

Arrays / Lists. In this section of notes you will be introduced to new type of variable that consists of other types. Types Of Variables

Arrays / Lists. In this section of notes you will be introduced to new type of variable that consists of other types. Types Of Variables Arrays / Lists In this section of notes you will be introduced to new type of variable that consists of other types. Types Of Variables Python variables 1. Simple (atomic) 2. Aggregate (composite) integer

More information

Lecture #13: More Sequences and Strings. Last modified: Tue Mar 18 16:17: CS61A: Lecture #13 1

Lecture #13: More Sequences and Strings. Last modified: Tue Mar 18 16:17: CS61A: Lecture #13 1 Lecture #13: More Sequences and Strings Last modified: Tue Mar 18 16:17:54 2014 CS61A: Lecture #13 1 Odds and Ends: Multi-Argument Map Python s built-in map function actually applies a function to one

More information

1 2 (3 + x 3) x 2 = 1 3 (3 + x 1 2x 3 ) 1. 3 ( 1 x 2) (3 + x(0) 3 ) = 1 2 (3 + 0) = 3. 2 (3 + x(0) 1 2x (0) ( ) = 1 ( 1 x(0) 2 ) = 1 3 ) = 1 3

1 2 (3 + x 3) x 2 = 1 3 (3 + x 1 2x 3 ) 1. 3 ( 1 x 2) (3 + x(0) 3 ) = 1 2 (3 + 0) = 3. 2 (3 + x(0) 1 2x (0) ( ) = 1 ( 1 x(0) 2 ) = 1 3 ) = 1 3 6 Iterative Solvers Lab Objective: Many real-world problems of the form Ax = b have tens of thousands of parameters Solving such systems with Gaussian elimination or matrix factorizations could require

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

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

CME 193: Introduction to Scientific Python Lecture 1: Introduction

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

More information

Pointers and Terminal Control

Pointers and Terminal Control Division of Mathematics and Computer Science Maryville College Outline 1 2 3 Outline 1 2 3 A Primer on Computer Memory Memory is a large list. Typically, each BYTE of memory has an address. Memory can

More information

CSCI-1200 Data Structures Fall 2017 Lecture 13 Problem Solving Techniques

CSCI-1200 Data Structures Fall 2017 Lecture 13 Problem Solving Techniques CSCI-1200 Data Structures Fall 2017 Lecture 13 Problem Solving Techniques Review from Lecture 12 Rules for writing recursive functions: 1. Handle the base case(s). 2. Define the problem solution in terms

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

Lists and Loops. browse Python docs and interactive help

Lists and Loops. browse Python docs and interactive help Lists and Loops 1 Help in Python browse Python docs and interactive help 2 Lists in Python defining lists lists as queues and stacks inserting and removing membership and ordering lists 3 Loops in Python

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

Combinatorics 3: Champions League draw

Combinatorics 3: Champions League draw Bachelor of Ecole Polytechnique Computational Mathematics, year 2, semester 1 Lecturer: Lucas Gerin (send mail) (mailto:lucas.gerin@polytechnique.edu) Combinatorics 3: Champions League draw Table of contents

More information

User-Defined Function

User-Defined Function ENGR 102-213 (Socolofsky) Week 11 Python scripts In the lecture this week, we are continuing to learn powerful things that can be done with userdefined functions. In several of the examples, we consider

More information

THE RELATIONSHIP BETWEEN PROCEDURAL GENERATION TECHNIQUES: CELLULAR AUTOMATA AND NOISE JESSE HIGNITE. Advisor DANIEL PLANTE

THE RELATIONSHIP BETWEEN PROCEDURAL GENERATION TECHNIQUES: CELLULAR AUTOMATA AND NOISE JESSE HIGNITE. Advisor DANIEL PLANTE THE RELATIONSHIP BETWEEN PROCEDURAL GENERATION TECHNIQUES: CELLULAR AUTOMATA AND NOISE by JESSE HIGNITE Advisor DANIEL PLANTE A senior research proposal submitted in partial fulfillment of the requirements

More information

Web Clients and Crawlers

Web Clients and Crawlers Web Clients and Crawlers 1 Web Clients alternatives to web browsers opening a web page and copying its content 2 Scanning Files looking for strings between double quotes parsing URLs for the server location

More information

Week 3. Sun Jun with slides from Hans Petter Langtangen

Week 3. Sun Jun with slides from Hans Petter Langtangen Week 3 Sun Jun with slides from Hans Petter Langtangen Nested lists: list of lists A list can contain any object, also another list Instead of storing a table as two separate lists (one for each column),

More information

CMPS 12A - Winter 2002 Midterm 2 March 5, Name: ID:

CMPS 12A - Winter 2002 Midterm 2 March 5, Name: ID: CMPS 12A - Winter 2002 Midterm 2 March 5, 2002 Name: ID: This is a closed note, closed book exam. Any place where you are asked to write code, you must declare all variables that you use. However, I just

More information

CSc 110, Spring 2017 Lecture 38: Critters. Adapted from slides by Marty Stepp and Stuart Reges

CSc 110, Spring 2017 Lecture 38: Critters. Adapted from slides by Marty Stepp and Stuart Reges CSc 110, Spring 2017 Lecture 38: Critters Adapted from slides by Marty Stepp and Stuart Reges 1 Calling overridden methods Subclasses can call overridden methods with super super(classname, self).method(parameters)

More information

BASICS OF GRAPHICAL APPS

BASICS OF GRAPHICAL APPS CSC 2014 Java Bootcamp Lecture 7 GUI Design BASICS OF GRAPHICAL APPS 2 Graphical Applications So far we ve focused on command-line applications, which interact with the user using simple text prompts In

More information

Outline. tallying the votes global and local variables call by value or call by reference. of variable length using keywords for optional arguments

Outline. tallying the votes global and local variables call by value or call by reference. of variable length using keywords for optional arguments Outline 1 Histograms tallying the votes global and local variables call by value or call by reference 2 Arguments of Functions of variable length using keywords for optional arguments 3 Functions using

More information

Search. The Nearest Neighbor Problem

Search. The Nearest Neighbor Problem 3 Nearest Neighbor Search Lab Objective: The nearest neighbor problem is an optimization problem that arises in applications such as computer vision, pattern recognition, internet marketing, and data compression.

More information

Front page. UNIVERSITY OF OSLO Faculty of mathematics and natural sciences

Front page. UNIVERSITY OF OSLO Faculty of mathematics and natural sciences Front page UNIVERSITY OF OSLO Faculty of mathematics and natural sciences Examination in: IN1900/INF1100 Introduction to programming for scientific applications Day of examination: December 18th 2017 Examination

More information

CS 1301 Exam 1 Answers Fall 2009

CS 1301 Exam 1 Answers Fall 2009 Page 1/6 CS 1301 Fall 2009 Exam 1 Your Name: I commit to uphold the ideals of honor and integrity by refusing to betray the trust bestowed upon me as a member of the Georgia Tech community. CS 1301 Exam

More information

Matrix Multiplication

Matrix Multiplication Matrix Multiplication CPS343 Parallel and High Performance Computing Spring 2013 CPS343 (Parallel and HPC) Matrix Multiplication Spring 2013 1 / 32 Outline 1 Matrix operations Importance Dense and sparse

More information

CS1110 Lab 5: Practice for A4 (Mar 8-9, 2016) First Name: Last Name: NetID:

CS1110 Lab 5: Practice for A4 (Mar 8-9, 2016) First Name: Last Name: NetID: CS1110 Lab 5: Practice for A4 (Mar 8-9, 2016) First Name: Last Name: NetID: The lab assignments are very important. Remember this: The lab problems feed into the assignments and the assignments define

More information

Exercise 4: Loops, Arrays and Files

Exercise 4: Loops, Arrays and Files Exercise 4: Loops, Arrays and Files worth 24% of the final mark November 4, 2004 Instructions Submit your programs in a floppy disk. Deliver the disk to Michele Zito at the 12noon lecture on Tuesday November

More information

Maximum Density Still Life

Maximum Density Still Life The Hebrew University of Jerusalem Computer Science department Maximum Density Still Life Project in course AI 67842 Mohammad Moamen Table of Contents Problem description:... 3 Description:... 3 Objective

More information

Intro to Programming. Unit 7. What is Programming? What is Programming? Intro to Programming

Intro to Programming. Unit 7. What is Programming? What is Programming? Intro to Programming Intro to Programming Unit 7 Intro to Programming 1 What is Programming? 1. Programming Languages 2. Markup vs. Programming 1. Introduction 2. Print Statement 3. Strings 4. Types and Values 5. Math Externals

More information

High-Performance Computing

High-Performance Computing Informatik und Angewandte Kognitionswissenschaft Lehrstuhl für Hochleistungsrechnen Thomas Fogal Prof. Dr. Jens Krüger High-Performance Computing http://hpc.uni-due.de/teaching/wt2014/nbody.html Exercise

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

ENGR 102 Engineering Lab I - Computation

ENGR 102 Engineering Lab I - Computation ENGR 102 Engineering Lab I - Computation Learning Objectives by Week 1 ENGR 102 Engineering Lab I Computation 2 Credits 2. Introduction to the design and development of computer applications for engineers;

More information

(Refer Slide Time: 02.06)

(Refer Slide Time: 02.06) Data Structures and Algorithms Dr. Naveen Garg Department of Computer Science and Engineering Indian Institute of Technology, Delhi Lecture 27 Depth First Search (DFS) Today we are going to be talking

More information

CS1 Lecture 2 Jan. 16, 2019

CS1 Lecture 2 Jan. 16, 2019 CS1 Lecture 2 Jan. 16, 2019 Contacting me/tas by email You may send questions/comments to me/tas by email. For discussion section issues, sent to TA and me For homework or other issues send to me (your

More information

Mandatory Exercise 1 INF3110

Mandatory Exercise 1 INF3110 Mandatory Exercise 1 INF3110 In this exercise, you are going to write a small interpreter for a simple language for controlling a robot on a 2-dimensional grid. The language is called ROBOL, a clever acronym

More information

Unit 7: Algorithms and Python CS 101, Fall 2018

Unit 7: Algorithms and Python CS 101, Fall 2018 Unit 7: Algorithms and Python CS 101, Fall 2018 Learning Objectives After completing this unit, you should be able to: Identify whether a sequence of steps is an algorithm in the strict sense. Explain

More information

High-Performance Computing

High-Performance Computing Informatik und Angewandte Kognitionswissenschaft Lehrstuhl für Hochleistungsrechnen Rainer Schlönvoigt Thomas Fogal Prof. Dr. Jens Krüger High-Performance Computing http://hpc.uni-duisburg-essen.de/teaching/wt2013/pp-nbody.html

More information

Michele Van Dyne Museum 204B CSCI 136: Fundamentals of Computer Science II, Spring

Michele Van Dyne Museum 204B  CSCI 136: Fundamentals of Computer Science II, Spring Michele Van Dyne Museum 204B mvandyne@mtech.edu http://katie.mtech.edu/classes/csci136 CSCI 136: Fundamentals of Computer Science II, Spring 2016 1 Review of Java Basics Data Types Arrays NEW: multidimensional

More information

Matrix Multiplication

Matrix Multiplication Matrix Multiplication CPS343 Parallel and High Performance Computing Spring 2018 CPS343 (Parallel and HPC) Matrix Multiplication Spring 2018 1 / 32 Outline 1 Matrix operations Importance Dense and sparse

More information

Model Solutions. COMP 102: Test 1. 6 April, 2016

Model Solutions. COMP 102: Test 1. 6 April, 2016 Family Name:.............................. Other Names:............................. ID Number:............................... Signature.................................. Model Solutions COMP 102: Test

More information

High Performance Computing: Tools and Applications

High Performance Computing: Tools and Applications High Performance Computing: Tools and Applications Edmond Chow School of Computational Science and Engineering Georgia Institute of Technology Lecture 15 Numerically solve a 2D boundary value problem Example:

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

CS , Fall 2003 Exam 2

CS , Fall 2003 Exam 2 Andrew login ID: Full Name: CS 15-213, Fall 2003 Exam 2 November 18, 2003 Instructions: Make sure that your exam is not missing any sheets, then write your full name and Andrew login ID on the front. Write

More information

Exercise Set Decide whether each matrix below is an elementary matrix. (a) (b) (c) (d) Answer:

Exercise Set Decide whether each matrix below is an elementary matrix. (a) (b) (c) (d) Answer: Understand the relationships between statements that are equivalent to the invertibility of a square matrix (Theorem 1.5.3). Use the inversion algorithm to find the inverse of an invertible matrix. Express

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

Emil Sekerinski, McMaster University, Winter Term 16/17 COMP SCI 1MD3 Introduction to Programming

Emil Sekerinski, McMaster University, Winter Term 16/17 COMP SCI 1MD3 Introduction to Programming Emil Sekerinski, McMaster University, Winter Term 16/17 COMP SCI 1MD3 Introduction to Programming Consider flooding a valley (dam break, tides, spring): what is the water level at specific points in the

More information

Random numbers are used to simulate uncertain events. INF1100 Lectures, Chapter 8: Random Numbers and Simple Games. Distribution of random numbers

Random numbers are used to simulate uncertain events. INF1100 Lectures, Chapter 8: Random Numbers and Simple Games. Distribution of random numbers Random numbers are used to simulate uncertain events INF00 Lectures, Chapter 8: Random Numbers and Simple Games Hans Petter Langtangen Simula Research Laboratory University of Oslo, Dept. of Informatics

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

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

Today. Homework 1 / Test 1 Making decisions in Java If statements If/Else ( Either-or ) statements Logical NOT operator

Today. Homework 1 / Test 1 Making decisions in Java If statements If/Else ( Either-or ) statements Logical NOT operator Today Homework 1 / Test 1 Making decisions in Java If statements If/Else ( Either-or ) statements Logical NOT operator BIT 115: Introduction To Programming 1 Something to Remember: In parameter order,

More information

Python review. 1 Python basics. References. CS 234 Naomi Nishimura

Python review. 1 Python basics. References. CS 234 Naomi Nishimura Python review CS 234 Naomi Nishimura The sections below indicate Python material, the degree to which it will be used in the course, and various resources you can use to review the material. You are not

More information

processing data from the web

processing data from the web processing data from the web 1 CTA Tables general transit feed specification stop identification and name finding trips for a given stop 2 CTA Tables in MySQL files in GTFS feed are tables in database

More information

List Comprehensions and Simulations

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

More information

Policy Iteration, Value Iteration, and Linear Programming

Policy Iteration, Value Iteration, and Linear Programming 151-0563-01 Dynamic Programming and Optimal Control (Fall 2018) Programming Exercise Topic: Infinite Horizon Problems Issued: Nov 22, 2018 Due: Dec 19, 2018 Rajan Gill(rgill@ethz.ch), Weixuan Zhang(wzhang@ethz.ch),

More information

from Recursion to Iteration

from Recursion to Iteration from Recursion to Iteration 1 Quicksort Revisited using arrays partitioning arrays via scan and swap recursive quicksort on arrays 2 converting recursion into iteration an iterative version with a stack

More information

: Principles of Imperative Computation Victor Adamchik. Practice Exam - I

: Principles of Imperative Computation Victor Adamchik. Practice Exam - I 15-122 Practice Exam - I Page 1 of 10 15-122 : Principles of Imperative Computation Victor Adamchik Practice Exam - I Name: Andrew ID: Answer the questions in the space provided following each question.

More information