EE 194/BIO 196: Modeling,simulating and optimizing biological systems

Slides:



Advertisements
Similar presentations
Dynamic Programming Lets begin by looking at the Fibonacci sequence.
Advertisements

Computer Science 1620 Multi-Dimensional Arrays. we used arrays to store a set of data of the same type e.g. store the assignment grades for a particular.
Sequence Alignment II CIS 667 Spring Optimal Alignments So we know how to compute the similarity between two sequences  How do we construct an.
Lecture 6 Sept 15, 09 Goals: two-dimensional arrays matrix operations circuit analysis using Matlab image processing – simple examples.
Table of Contents Matrices - Multiplication Assume that matrix A is of order m  n and matrix B is of order p  q. To determine whether or not A can be.
Multi-Dimensional Arrays in Java "If debugging is the process of removing software bugs, then programming must be the process of putting them in." -- Edsger.
ARRAY REFERENCING 1 1. II. Array Referencing Assume an array has values. It is useful to “refer to” the elements contained within it – as smaller portions.
MATRICES Independent Study Developed by: B. deTreville Highland Springs High School.
Lecture 5.2: Special Graphs and Matrix Representation CS 250, Discrete Structures, Fall 2013 Nitesh Saxena Adopted from previous lectures by Zeph Grunschlag.
TA SURVEY Have the TA write their name on the board Fill out the survey at: The TA should walk out 5 minutes.
Warm Up Perform the indicated operations. If the matrix does not exist, write impossible
Arrays.
Module 1: Array ITEI222 - Advance Programming Language.
Dr. Sajib Datta CSE 1320 Arrays, Search and Sort.
Arrays.
Topic: Python Lists – Part 1
The Hungarian algorithm for non-square arrays
13.4 Product of Two Matrices
EGR 2261 Unit 10 Two-dimensional Arrays
Lecture 8: 2D Arrays and Nested Loops
Arrays.
May 17th – Comparison Sorts
Lecture 5.2: Special Graphs and Matrix Representation
Mesh connected networks. Sorting algorithms
CMSC201 Computer Science I for Majors Lecture 12 – Lists (cont)
Lecture No.43 Data Structures Dr. Sohail Aslam.
Arrays An Array is an ordered collection of variables
7.3 Matrices.
Numerical Computing in Python
Patterns and Relationships in Tables
Writing Methods AP Computer Science A.
Python: Array Slicing Damian Gordon.
CSE373: Data Structures & Algorithms Lecture 14: Hash Collisions
1020: Introduction to Programming Mohamed Shehata November 22, 2017
Engr 0012 (04-1) LecNotes
Java Programming Arrays
2.2 Introduction to Matrices
MATLAB Programming Indexing Copyright © Software Carpentry 2011
Arrays Chapter 8 Copyright © 2008 W. W. Norton & Company.
Array Creation ENGR 1181 MATLAB 02.
Multidimensional array
MATLAB Programming Basics Copyright © Software Carpentry 2011
ARRAYS 2 GCSE COMPUTER SCIENCE.
Algorithms CSCI 235, Spring 2019 Lecture 28 Dynamic Programming III
EECE.2160 ECE Application Programming
Algorithmic complexity: Speed of algorithms
The Hungarian algorithm for non-square arrays
Data Structures & Algorithms
Multi-Dimensional Arrays
15-110: Principles of Computing
EECE.2160 ECE Application Programming
EE 194/BIO 196: Modeling,simulating and optimizing biological systems
EE 194/Bio 196 Modeling,simulating and optimizing biological systems
Biologically Inspired Computing: Operators for Evolutionary Algorithms
Matrix A matrix is a rectangular arrangement of numbers in rows and columns Each number in a matrix is called an Element. The dimensions of a matrix are.
Arrays in MatLab Arrays can have any number dimensions
EE 194/BIO 196: Modeling,simulating and optimizing biological systems
Working with Arrays in MATLAB
EE 155 / COMP 122: Parallel Computing
EE 194 / Bio 196: Modeling biological systems
EECE.2160 ECE Application Programming
EE 194/BIO 196: Modeling,simulating and optimizing biological systems
EE 194/Bio 196: Modeling biological systems
EE 194/BIO 196: Modeling biological systems
EECE.3220 Data Structures Instructor: Dr. Michael Geiger Spring 2017
Starter.
ENERGY 211 / CME 211 Lecture 11 October 15, 2008.
EECE.2160 ECE Application Programming
EE 193/Comp 150 Computing with Biological Parts
EE 194/Bio 196: Modeling,simulating and optimizing biological systems
Presentation transcript:

EE 194/BIO 196: Modeling,simulating and optimizing biological systems Spring 2018 Tufts University Instructor: Joel Grodstein joel.grodstein@tufts.edu 2D arrays

Arrays so far We’ve already used arrays – but just in “1D” HW1 = np.array([90,99,60,90]) HW1[0]=90 HW1[3]=60 One homework, four students Next up: add an extra dimension (so, “2D”) Use an egg carton again 90 99 60 90 [0] [1] [2] [3] EE 194/Bio 196 Joel Grodstein

2D arrays Think of a 2D array as a table of numbers 3 homeworks, 4 students Each row is a homework Each column is a student How do I access it? HW[0,2] is 60 HW[1,2] is 55 HW[2,1] is How do I build it? HW = np.array ([[90,99,60,90],[91,80,55,93],[89,80,99,93]]) [0] [1] [2] 90 99 60 90 91 80 55 93 89 80 99 93 [0] [1] [2] [3] 80 EE 194/Bio 196 Joel Grodstein

2D arrays Another way to build it: HW = np.zeros ((3,4)) [0] [1] [2] 90 99 60 90 [0] [1] [2] [3] EE 194/Bio 196 Joel Grodstein

2D arrays Another way to build it: HW = np.zeros ((3,4)) (just “:” means the whole row) [0] [1] [2] 90 99 60 90 91 80 55 93 [0] [1] [2] [3] EE 194/Bio 196 Joel Grodstein

Reading 2D arrays Read it as usual: print (HW[0,0:4]) print (HW[1,:]) [0] [1] [2] 90 99 60 90 91 80 55 93 [0] [1] [2] [3] Read it as usual: print (HW[0,0:4]) print (HW[1,:]) print (HW[2,:]) [90,99,60,90] [91,80,55,93] [0,0,0,0] EE 194/Bio 196 Joel Grodstein

More slice access HW[1,1:] HW[1:3,2] HW[1:3,2:] 80 55 93 90 99 60 90 [0] [1] [2] 80 55 93 90 99 60 90 91 80 55 93 55 [0] [1] [2] [3] 55 93 EE 194/Bio 196 Joel Grodstein

Modify one element Assume we’ve set HW[2,:]=[89,80,99,93] HW[1,2]=90 error [0] [1] [2] 90 99 60 90 91 80 55 90 93 50 89 80 99 93 [0] [1] [2] [3] EE 194/Bio 196 Joel Grodstein

Still more slice access copy a row HW[2,:] = HW[1,:] copy two columns HW[:,2:4] = HW[:,0:2] [0] [1] [2] 90 99 60 90 91 91 80 55 93 80 55 93 89 80 99 93 [0] [1] [2] [3] [0] [1] [2] 90 90 99 91 80 89 99 60 90 91 80 55 93 89 80 99 93 [0] [1] [2] [3] EE 194/Bio 196 Joel Grodstein

Remember our problem with arrays? a1 = np.array ([2,4,6]) a2 = a1 a2[1]=1 print (a2) print (a1) a2 = np.array ([2,4,6]) We’ll learn more strategies to beat this problem later [2, 4, 6] Now a2=[2, 4, 6] [2, 1, 6] [2, 1, 6] Now we have two different egg cartons [2, 1, 6] “Later” has now arrived [2, 4, 6] EE 194/Bio 196 Joel Grodstein

Copying an array a1 = np.array ([2,4,6]) a2 = np.array ([2,4,6]) print (a2) print (a1) And this works just as well with 2D arrays. We’ll use it in the Manduca HW Now we have two different egg cartons a1.copy() [2, 1, 6] [2, 4, 6] EE 194/Bio 196 Joel Grodstein

Looping through an array Remember how we looped through an array? ar = np.array ([1,3,5]) for i in ar: What happens if we loop through a 2D array? ar = np.array ([[1,3,5],[11,13,15]]) What if you want to loop through every element of a 2D array? for i in ar.flat: i becomes 1, 3 and then 5 i becomes [1,3,5] and then [11,13,15] i becomes 1, 3, 5, 11, 13 and finally 15 EE 194/Bio 196 Joel Grodstein

Advanced indexing Python has advanced indexing capabilities that mirror Matlab HW [ HW<65] += 10 HW [2, HW[2,:]>90] = 0 [0] [1] [2] 90 99 70 60 90 91 80 65 55 93 89 80 99 93 [0] [1] [2] [3] EE 194/Bio 196 Joel Grodstein

Advanced indexing Advanced indexing can build a 2D array from elements of a 1D array: ar_1D = np.array ([2,4,6,8]) indices = np.array ([[1,1][2,3]]) ar_2D = ar_1D [indices] It can also do the reverse: ar_1D = ar_2D [ [0,1,1], [0,1,0] ] 4 4 6 8 4 8 6 EE 194/Bio 196 Joel Grodstein

Group exercise Given: two arrays ar1 and ar2 Each one is 10 rows and 4 columns Build an array ar3 that has even rows from ar1, odd from ar2 Make sure that changing ar3 will not change ar1 or ar2 Lookahead: this will be similar to a genetic algorithm EE 194/Bio 196 Joel Grodstein

Another group exercise Given: one 10x4 array ar1 Pick a random pair of rows (e.g., rows 0&1) Replicate it forwards (i.e., so rows 2&3 become identical to 0&1) Make sure not to try to copy, e.g., rows 7&8 to rows 9 & 10 Since there is no row #10! (This may be useful for genetic mutations) EE 194/Bio 196 Joel Grodstein

Follow-up activities Try the examples from this lecture yourself Vary them, or even mis-type some to see what happens More exercises. Write a program that… Creates an NxN array with 1 on the border and 0 inside Creates an 8x8 array and fills it with a checkerboard pattern Finds the indices of the maximum and minimum values in a 2D array Creates an NxN cyclic matrix [[0 1 2 3 4] [1 2 3 4 0][2 3 4 0 1] ...]. Then double every element and print it. Prints the odd columns of a 2D array EE 194/Bio 196 Joel Grodstein