2-Dimensional Lists (Matrices) in Python

Slides:



Advertisements
Similar presentations
2.3 Modeling Real World Data with Matrices
Advertisements

Section 13-4: Matrix Multiplication
Two-Dimensional Arrays Chapter What is a two-dimensional array? A two-dimensional array has “rows” and “columns,” and can be thought of as a series.
Lists CMSC 201. Overview Today we will learn about: For loops.
Matrix Multiplication, Part 2a V T S Pizza Drink Salad What if your group wants to buy 1 pizza, 3 drinks, and 3 salads? Or 2 pizzas, 4 drinks, and 3 salads?
Maths for Computer Graphics
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.
Row 1 Row 2 Row 3 Row m Column 1Column 2Column 3 Column 4.
COMPUTER SCIENCE FEBRUARY 2011 Lists in Python. Introduction to Lists Lists (aka arrays): an ordered set of elements  A compound data type, like strings.
Row 1 Row 2 Row 3 Row m Column 1Column 2Column 3 Column 4.
Two dimensional arrays in Java Computer Science 3 Gerb Objective: Use matrices in Java.
CHAPTER: 12. Array is a collection of variables of the same data type that are referenced by a common name. An Array of 10 Elements of type double.
Two –Dimensional Arrays Mrs. C. Furman September 18, 2008.
Class Opener:. Identifying Matrices Student Check:
PYTHON LISTS. What are lists? An ordered set of elements A variable with 0 or more things inside of it Examples myList = [8, 6, 7, 5, 3, 0, 9] strList.
Computing Science 1P Large Group Tutorial 13 Simon Gay Department of Computing Science University of Glasgow 2006/07.
For Loops CMSC 201. Overview Today we will learn about: For loops.
3.6 Solving Systems Using Matrices You can use a matrix to represent and solve a system of equations without writing the variables. A matrix is a rectangular.
Section 4.3 – Multiplying Matrices. MATRIX MULTIPLICATION 1. The order makes a difference…AB is different from BA. 2. The number of columns in first matrix.
Table of Contents Matrices - Definition and Notation A matrix is a rectangular array of numbers. Consider the following matrix: Matrix B has 3 rows and.
Notes Over 4.2 Finding the Product of Two Matrices Find the product. If it is not defined, state the reason. To multiply matrices, the number of columns.
Do Now: Perform the indicated operation. 1.). Algebra II Elements 11.1: Matrix Operations HW: HW: p.590 (16-36 even, 37, 44, 46)
Chapter 4 Section 1 Organizing Data into Matrices.
Python Fundamentals: Complex Data Structures Eric Shook Department of Geography Kent State University.
1 Arrays and Variable Length Parameter List  The syntax to declare a variable length formal parameter (list) is: dataType... identifier.
Copyright © 2014, 2010, 2007 Pearson Education, Inc.
13.4 Product of Two Matrices
12-1 Organizing Data Using Matrices
Chapter 8: Arrays Starting Out with C++ Early Objects Ninth Edition
Two-dimensional arrays
CMSC201 Computer Science I for Majors Lecture 12 – Lists (cont)
Matrix Operations.
Warm-Up - 8/30/2010 Simplify. 1.) 2.) 3.) 4.) 5.)
Matrix 2015/11/18 Hongfei Yan zip(*a) is matrix transposition
Matrix Multiplication
Matrix Operations.
Matrix 2016/11/30 Hongfei Yan zip(*a) is matrix transposition
2-D Lists Taken from notes by Dr. Neil Moore
Multiplying Matrices.
Lists in Python.
Introduction to Matrices
Matrices Elements, Adding and Subtracting
CSCI N207 Data Analysis Using Spreadsheet
Multidimensional Arrays
Data Structures – 2D Lists
( ) ( ) ( ) ( ) Matrices Order of matrices
Lists in Python Outputting lists.
Objectives Multiply two matrices.
Multidimensional array
Multidimensional Arrays
Multiplying Matrices.
Lets Play with arrays Singh Tripty
Multi-Dimensional Arrays
Dimensions matching Rows times Columns
3.6 Multiply Matrices.
Introduction to Computer Science
EECS Introduction to Computing for the Physical Sciences
1.8 Matrices.
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
1.8 Matrices.
Multiplying Matrices.
Working with Arrays in MATLAB
Multiplying Matrices.
2-D Lists Taken from notes by Dr. Neil Moore
Matrix Multiplication Sec. 4.2
Multiplying Matrices.
Announcements.
Tuple.
Presentation transcript:

2-Dimensional Lists (Matrices) in Python

List Review emptyList = [] print(len(emptyList)) #displays 0, the size of emptyList myList = [8, 6, 7, 5, 3, 0, 9] print(myList[0]) #displays 8 by accessing the 0th-element print(myList[3]) #displays 5 by accessing the 3th-element print(len(myList)) #displays 7, the size of myList myList[5] = 4 #changes the 0 in the list to 4 #[8, 6, 7, 5, 3, 4, 9]

What if elements in a list are lists? matrix = [ [1, 3, 5], [2, 4, 6] ] print(matrix[0]) #gives you the entire 0th-element, which is [1, 3, 5] # How do we access an element inside of the inner list? # Use a second set of brackets to access an inner list’s elements print(matrix[0][1]) #gives you 3

Another way to show a 2-D list matrix = [ [1, 5, 9], [2, 4, 6], [8, 5, 3] ] # This looks a little more aesthetic and easier to read # Each inner list is a row # Within each row are column elements # Access individual elements by using matrix[ROW][COL]

Changing elements matrix = [ [1, 5, 9], [2, 4, 6], [8, 5, 3] ] matrix[2][1] = 0 #changes the row-2, col-1 to 0 #[ [1, 5, 9], # [2, 4, 6], # [8, 0, 3] ]

len() and matrices matrix = [ [1, 3, 5], [2, 4, 6] ] print(len(matrix)) #len() will return 2 print(len(matrix[1])) #len() will return 3

Looping! matrix = [ [1, 5, 9], [2, 4, 6], [8, 5, 3] ] for r in range(3): #iterate through each row index for c in range(3): #iterate through each col index print(matrix[r][c]) #access the specific element