Two-dimensional arrays

Slides:



Advertisements
Similar presentations
UNIT IV.
Advertisements

CPS120: Introduction to Computer Science Arrays. Arrays: A Definition A list of variables accessed using a single identifier May be of any data type Can.
Lists in Python.
Two dimensional arrays in Java Computer Science 3 Gerb Objective: Use matrices in Java.
CPS120: Introduction to Computer Science Lecture 15 Arrays.
IN THE NAME OF ALLAH WHO IS THE MOST BENEFICENT AND MOST MERCIFUL.
Chapter 6Java: an Introduction to Computer Science & Programming - Walter Savitch 1 Chapter 6 l Array Basics l Arrays in Classes and Methods l Programming.
Chapter 8: Part 3 Collections and Two-dimensional arrays.
Linear Containers Some containers are called linear because their content (items) are stored in a single row (line). Which of the following are linear?
EGR 2261 Unit 10 Two-dimensional Arrays
What Comes in Arrays?.
Lecture 8: 2D Arrays and Nested Loops
Two-Dimensional Arrays
Chapter 7 Matrix Mathematics
Topic Dimensional Arrays
Computer Programming BCT 1113
Microsoft Visual Basic 2005: Reloaded Second Edition
multi-dimensional arrays
Two Dimensional Arrays
Unit 1: Matrices Day 1 Aug. 7th, 2012.
2-D Lists Taken from notes by Dr. Neil Moore
Lists in Python Parallel lists.
Presentation Test. Second Slide Third Slide It worked.
Two-Dimensional Arrays
Pointers and Arrays S.Bhuvaneshwari Assistant Professor/CSE
Multiplying Matrices.
Lists in Python.
Example Problems for Exam#2 (covers chapters 5, 6, 7, 8, 9)
2D Arrays October 12, 2007 ComS 207: Programming I (in Java)
Topic 26 Two Dimensional Arrays
Introduction to Matrices
Multiplying Matrices.
4-1 Organizing Data Into Matrices
Coding Concepts (Data Structures)
Introduction To Programming Information Technology , 1’st Semester
CSCI N207 Data Analysis Using Spreadsheet
Multidimensional Arrays
Data Structures – 2D Lists
Arrays Chapter 8 Copyright © 2008 W. W. Norton & Company.
MSIS 655 Advanced Business Applications Programming
Calendar like the Periodic Table
Lecture 4 2d Arrays CSE /26/2018.
Unit 1 MATRICES Dr. Shildneck Fall, 2015.
Multidimensional Arrays
Multidimensional array
Arrays.
Multidimensional Arrays
Multiplying Matrices.
Multi-Dimensional Arrays
EXCEL Creating An Array In VBA
Multi-Dimensional Arrays
Program Design Invasion Percolation: The Grid
Dimensions matching Rows times Columns
2-Dimensional Lists (Matrices) in Python
Introduction to Computer Science
2d Arrays.
EECS Introduction to Computing for the Physical Sciences
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.
C++ Array 1.
Database SQL.
Multiplying Matrices.
Working with Arrays in MATLAB
Multiplying Matrices.
2-D Lists Taken from notes by Dr. Neil Moore
Dr. Khizar Hayat Associate Prof. of Computer Science
Fast-Track UiPath Developer Module 4: Retrieving and Working With Data
Multiplying Matrices.
Announcements.
Chapter 6 - Arrays Outline Multiple-Subscripted Arrays.
Presentation transcript:

Two-dimensional arrays Lists in Python Two-dimensional arrays

Two dimensions You will sometimes have data which has a two-dimensional structure (days and hours for example, or rows and columns) You could store the data in one big list and keep track of the structure some other way but most modern languages provide a way to express the two dimensions directly

List of lists In Python you can think of this structure as a list of lists mat = [[1,2,3], [5, 9, 2], [7, 8, 3], [6, 7, 0]] Of course in Python any of these lists can be any size (they don’t all have to be 3 elements long!) Typically a 2-d array is thought of as having so many rows and so many columns (a grid like Excel)

Syntax of 2-d arrays One way to create a 2-d array is as given on the last slide, just write it out Another that is quicker if you want to initialize all elements to one value: mat2 = [[0] * 3 for i in range(4)] creates a 2-d array with 4 rows, 3 columns full of zeros O

Accessing elements of a 2-d array You use two subscripts, each in a pair of [] mat [2][1] is the element in the third row and second column – just like 1-d arrays, they start numbering at [0][0]