SlideShare a Scribd company logo
2
Most read
4
Most read
Module 2
Data Collections – Lists, Tuples,
and Dictionaries
Multidimensional arrays
Module 2 Multidimensional arrays
Lists in lists
row = []
for i in range(8):
row.append(WHITE_PAWN)
row = [WHITE_PAWN for i in range(8)]
squares = [x ** 2 for x in range(10)]
#output [0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
twos = [2 ** i for i in range(8)]
#output [1, 2, 4, 8, 16, 32, 64, 128]
squares = [x ** 2 for x in range(10)]
odds = [x for x in squares if x % 2 != 0 ]
print(odds)
#output [1, 9, 25, 49, 81]
Module 2 Multidimensional arrays
Two-dimensional arrays
board = []
for i in range(8):
row = [EMPTY for i in range(8)]
board.append(row)
EMPTY = "-"
ROOK = "ROOK"
board = []
for i in range(8):
row = [EMPTY for i in range(8)]
board.append(row)
board[0][0] = ROOK
board[0][7] = ROOK
board[7][0] = ROOK
board[7][7] = ROOK
print(board)
board = [[EMPTY for i in range(8)] for j in range(8)]
Module 2 Multidimensional arrays
Multidimensional nature of lists
two
coordinates
a vertical one
(row number)
a horizontal
one (column
number)
temps = [[0.0 for h in range(24)] for d in range(31)]
# The matrix is magically updated here.
total = 0.0
for day in temps:
total += day[11]
average = total / 31
print("Average temperature at noon:", average)
The monthly average noon temperature
Module 2 Multidimensional arrays
Multidimensional nature of lists
temps = [[0.0 for h in range(24)] for d in range(31)]
# The matrix is magically updated here.
highest = -100.0
for day in temps:
for temp in day:
if temp > highest:
highest = temp
print("The highest temperature was:", highest)
The highest temperature
Module 2 Multidimensional arrays
Multidimensional nature of lists
temps = [[0.0 for h in range(24)] for d in range(31)]
# The matrix is magically updated here.
hot_days = 0
for day in temps:
if day[11] > 20.0:
hot_days += 1
print(hot_days, "days were hot.")
The days when the temperature at noon was at least 20 ℃
Module 2 Multidimensional arrays
Three-dimensional arrays
• three buildings
• 15 floors each
• 20 rooms on each floor
the type of the array's elements(True/False)
calm analysis of the situation
rooms = [[[False for r in range(20)] for f in
range(15)] for t in range(3)]
In the second building,
on the tenth floor, room
14:
rooms[1][9][13] = True
Module 2 Multidimensional arrays
Key takeaways 1
[expression for element in list if conditional]
# A four-column/four-row table - a two
dimensional array (4x4)
table = [[":(", ":)", ":(", ":)"],
[":)", ":(", ":)", ":)"],
[":(", ":)", ":)", ":("],
[":)", ":)", ":)", ":("]]
print(table)
print(table[0][0]) # outputs: ':('
print(table[0][3]) # outputs: ':)'
list comprehension
use nested lists to
create matrices
Module 2 Multidimensional arrays
Key takeaways 2
# Cube - a three-dimensional array (3x3x3)
cube = [[[':(', 'x', 'x'],
[':)', 'x', 'x'],
[':(', 'x', 'x']],
[[':)', 'x', 'x'],
[':(', 'x', 'x'],
[':)', 'x', 'x']],
[[':(', 'x', 'x'],
[':)', 'x', 'x'],
[':)', 'x', 'x']]]
print(cube)
print(cube[0][0][0]) # outputs: ':('
print(cube[2][2][0]) # outputs: ':)'
create n-dimensional
lists
Congratulations!
You have completed Module 2
Well done! You've reached the end of Module 2
and completed a major milestone in your Python
programming education.
Ad

Recommended

PPT
Chapter2
Nashra Akhter
 
PDF
Programs in array using SWIFT
vikram mahendra
 
PDF
Excel macro for solving a polynomial equation
Upendra Lele
 
PPT
Multi dimensional arrays
Aseelhalees
 
PDF
Ch18 18
schibu20
 
PPTX
Constraint propagation
Peet Denny
 
PDF
SPL 12 | Multi-dimensional Array in C
Mohammad Imam Hossain
 
PPTX
Multi-Dimensional Lists
primeteacher32
 
PDF
Coding Test Review1
SEMINARGROOT
 
DOCX
Derivative investigation
jchartiersjsd
 
PDF
Lr5
metallurg056
 
DOCX
Fungsi kuadrat
selviayunistin
 
PDF
Examen final (2 d 10)
ACceresMamani
 
PPTX
10.5 more on language of functions x
math260
 
PPTX
Matlab ploting
Ameen San
 
DOCX
Function
KAZEMBETVOnline
 
PDF
Day 6 examples
jchartiersjsd
 
PPT
Lecture 16 - Multi dimensional Array
Md. Imran Hossain Showrov
 
PDF
Coding test review
KyuyongShin
 
PDF
1 13s-f
Kamarat Kumanukit
 
DOCX
Introduction to r
Golden Julie Jesus
 
PDF
Day 7 examples u6w14
jchartiersjsd
 
PPTX
2D arrays
Mehedi Hasan Raju
 
PPT
How to graph Functions
coolhanddav
 
PPTX
Matlab plotting
shahid sultan
 
PPTX
11 graphs of first degree functions x
math260
 
PDF
Chapter 8_Array.pdf
marifmohmd
 
PPTX
ARRAY OPERATIONS.pptx
DarellMuchoko
 
PDF
Unit-5-Part1 Array in Python programming.pdf
582004rohangautam
 
PDF
Python programming : Arrays
Emertxe Information Technologies Pvt Ltd
 

More Related Content

What's hot (18)

PDF
Coding Test Review1
SEMINARGROOT
 
DOCX
Derivative investigation
jchartiersjsd
 
PDF
Lr5
metallurg056
 
DOCX
Fungsi kuadrat
selviayunistin
 
PDF
Examen final (2 d 10)
ACceresMamani
 
PPTX
10.5 more on language of functions x
math260
 
PPTX
Matlab ploting
Ameen San
 
DOCX
Function
KAZEMBETVOnline
 
PDF
Day 6 examples
jchartiersjsd
 
PPT
Lecture 16 - Multi dimensional Array
Md. Imran Hossain Showrov
 
PDF
Coding test review
KyuyongShin
 
PDF
1 13s-f
Kamarat Kumanukit
 
DOCX
Introduction to r
Golden Julie Jesus
 
PDF
Day 7 examples u6w14
jchartiersjsd
 
PPTX
2D arrays
Mehedi Hasan Raju
 
PPT
How to graph Functions
coolhanddav
 
PPTX
Matlab plotting
shahid sultan
 
PPTX
11 graphs of first degree functions x
math260
 
Coding Test Review1
SEMINARGROOT
 
Derivative investigation
jchartiersjsd
 
Fungsi kuadrat
selviayunistin
 
Examen final (2 d 10)
ACceresMamani
 
10.5 more on language of functions x
math260
 
Matlab ploting
Ameen San
 
Function
KAZEMBETVOnline
 
Day 6 examples
jchartiersjsd
 
Lecture 16 - Multi dimensional Array
Md. Imran Hossain Showrov
 
Coding test review
KyuyongShin
 
Introduction to r
Golden Julie Jesus
 
Day 7 examples u6w14
jchartiersjsd
 
How to graph Functions
coolhanddav
 
Matlab plotting
shahid sultan
 
11 graphs of first degree functions x
math260
 

Similar to Python PCEP Multidemensional Arrays (20)

PDF
Chapter 8_Array.pdf
marifmohmd
 
PPTX
ARRAY OPERATIONS.pptx
DarellMuchoko
 
PDF
Unit-5-Part1 Array in Python programming.pdf
582004rohangautam
 
PDF
Python programming : Arrays
Emertxe Information Technologies Pvt Ltd
 
DOCX
Numpy in Python.docx
manohar25689
 
PDF
Numpy intro presentation for college.pdf
kakkarskrishna22
 
PPTX
Outlier Packaging Vault on what is bases
newwesta48
 
PPTX
Nested lists (Two dimensional lists for Python)
abzalbekulasbekov
 
PPTX
Python PCEP Lists Collections of Data
IHTMINSTITUTE
 
PPTX
Pa1 session 3_slides
aiclub_slides
 
PPTX
Python - Numpy/Pandas/Matplot Machine Learning Libraries
Andrew Ferlitsch
 
PDF
Matplotlib adalah pustaka plotting 2D Python yang menghasilkan gambar berkual...
HendraPurnama31
 
PPTX
Week 11.pptx
CruiseCH
 
PPTX
object oriented programing in python and pip
LakshmiMarineni
 
PDF
Numpy - Array.pdf
AnkitaArjunDevkate
 
PPTX
python-numwpyandpandas-170922144956.pptx
smartashammari
 
PPTX
Python PPT.pptx
KanwerpreetSingh1
 
PPTX
python-numpyandpandas-170922144956 (1).pptx
Akashgupta517936
 
PDF
Python Tutorial
Eueung Mulyana
 
PDF
Migrating from matlab to python
ActiveState
 
Chapter 8_Array.pdf
marifmohmd
 
ARRAY OPERATIONS.pptx
DarellMuchoko
 
Unit-5-Part1 Array in Python programming.pdf
582004rohangautam
 
Python programming : Arrays
Emertxe Information Technologies Pvt Ltd
 
Numpy in Python.docx
manohar25689
 
Numpy intro presentation for college.pdf
kakkarskrishna22
 
Outlier Packaging Vault on what is bases
newwesta48
 
Nested lists (Two dimensional lists for Python)
abzalbekulasbekov
 
Python PCEP Lists Collections of Data
IHTMINSTITUTE
 
Pa1 session 3_slides
aiclub_slides
 
Python - Numpy/Pandas/Matplot Machine Learning Libraries
Andrew Ferlitsch
 
Matplotlib adalah pustaka plotting 2D Python yang menghasilkan gambar berkual...
HendraPurnama31
 
Week 11.pptx
CruiseCH
 
object oriented programing in python and pip
LakshmiMarineni
 
Numpy - Array.pdf
AnkitaArjunDevkate
 
python-numwpyandpandas-170922144956.pptx
smartashammari
 
Python PPT.pptx
KanwerpreetSingh1
 
python-numpyandpandas-170922144956 (1).pptx
Akashgupta517936
 
Python Tutorial
Eueung Mulyana
 
Migrating from matlab to python
ActiveState
 
Ad

More from IHTMINSTITUTE (18)

PPTX
Python PCEP Tuples and Dictionaries
IHTMINSTITUTE
 
PPTX
Python PCEP Tuples and Dictionaries
IHTMINSTITUTE
 
PPTX
Python PCEP Creating Simple Functions
IHTMINSTITUTE
 
PPTX
Python PCEP Functions And Scopes
IHTMINSTITUTE
 
PPTX
Python PCEP Function Parameters
IHTMINSTITUTE
 
PPTX
Python PCEP Functions
IHTMINSTITUTE
 
PPTX
Python PCEP Operations On Lists
IHTMINSTITUTE
 
PPTX
Python PCEP Sorting Simple Lists
IHTMINSTITUTE
 
PPTX
Python PCEP Logic Bit Operations
IHTMINSTITUTE
 
PPTX
Python PCEP Loops
IHTMINSTITUTE
 
PPTX
Python PCEP Comparison Operators And Conditional Execution
IHTMINSTITUTE
 
PPTX
Python PCEP How To Talk To Computer
IHTMINSTITUTE
 
PPTX
Python PCEP Variables
IHTMINSTITUTE
 
PPTX
Python PCEP Operators
IHTMINSTITUTE
 
PPTX
Python PCEP Literals
IHTMINSTITUTE
 
PPTX
IHTM Python PCEP Hello World
IHTMINSTITUTE
 
PPTX
IHTM Python PCEP Introduction to Python
IHTMINSTITUTE
 
PPTX
Python PCEP Welcome Opening
IHTMINSTITUTE
 
Python PCEP Tuples and Dictionaries
IHTMINSTITUTE
 
Python PCEP Tuples and Dictionaries
IHTMINSTITUTE
 
Python PCEP Creating Simple Functions
IHTMINSTITUTE
 
Python PCEP Functions And Scopes
IHTMINSTITUTE
 
Python PCEP Function Parameters
IHTMINSTITUTE
 
Python PCEP Functions
IHTMINSTITUTE
 
Python PCEP Operations On Lists
IHTMINSTITUTE
 
Python PCEP Sorting Simple Lists
IHTMINSTITUTE
 
Python PCEP Logic Bit Operations
IHTMINSTITUTE
 
Python PCEP Loops
IHTMINSTITUTE
 
Python PCEP Comparison Operators And Conditional Execution
IHTMINSTITUTE
 
Python PCEP How To Talk To Computer
IHTMINSTITUTE
 
Python PCEP Variables
IHTMINSTITUTE
 
Python PCEP Operators
IHTMINSTITUTE
 
Python PCEP Literals
IHTMINSTITUTE
 
IHTM Python PCEP Hello World
IHTMINSTITUTE
 
IHTM Python PCEP Introduction to Python
IHTMINSTITUTE
 
Python PCEP Welcome Opening
IHTMINSTITUTE
 
Ad

Recently uploaded (20)

PPTX
BASICS OF SAP _ ALL ABOUT SAP _WHY SAP OVER ANY OTHER ERP SYSTEM
AhmadAli716831
 
PPTX
Azure_Landing_Zone_Best_Practices_Visuals.pptx
fredsonbarbosa1
 
PPTX
The ARUBA Kind of new Proposal Umum .pptx
andiwarneri
 
PDF
Slides: Eco Economic Epochs for The World Game (s) pdf
Steven McGee
 
PDF
Transmission Control Protocol (TCP) and Starlink
APNIC
 
PPTX
最新版加拿大奎斯特大学毕业证(QUC毕业证书)原版定制
taqyed
 
PDF
Paper: The World Game (s) Great Redesign.pdf
Steven McGee
 
PDF
DDoS in India, presented at INNOG 8 by Dave Phelan
APNIC
 
PPTX
BitRecover OST to PST Converter Software
antoniogosling01
 
PDF
BroadLink Cloud Service introduction.pdf
DevendraDwivdi1
 
PPTX
IAREUOUSTPIDWHY$)CHARACTERARERWUEEJJSKWNSND
notgachabite123
 
PPTX
ChatGPT_and_Its_Uses_Presentationss.pptx
Neha Prakash
 
PDF
Clive Dickens RedTech Public Copy - Collaborate or Die
Clive Dickens
 
PDF
B M Mostofa Kamal Al-Azad [Document & Localization Expert]
Mostofa Kamal Al-Azad
 
PPTX
原版一样(ANU毕业证书)澳洲澳大利亚国立大学毕业证在线购买
Taqyea
 
PPTX
Q1 English3 Week5 [email protected]
JenniferCawaling1
 
PPTX
history of internet in nepal Class-8 (sparsha).pptx
SPARSH508080
 
PPT
Almos Entirely Correct Mixing with Apps to Voting
gapati2964
 
PPTX
原版一样(ISM毕业证书)德国多特蒙德国际管理学院毕业证多少钱
taqyed
 
PDF
ChatGPT A.I. Powered Chatbot and Popularization.pdf
StanleySamson1
 
BASICS OF SAP _ ALL ABOUT SAP _WHY SAP OVER ANY OTHER ERP SYSTEM
AhmadAli716831
 
Azure_Landing_Zone_Best_Practices_Visuals.pptx
fredsonbarbosa1
 
The ARUBA Kind of new Proposal Umum .pptx
andiwarneri
 
Slides: Eco Economic Epochs for The World Game (s) pdf
Steven McGee
 
Transmission Control Protocol (TCP) and Starlink
APNIC
 
最新版加拿大奎斯特大学毕业证(QUC毕业证书)原版定制
taqyed
 
Paper: The World Game (s) Great Redesign.pdf
Steven McGee
 
DDoS in India, presented at INNOG 8 by Dave Phelan
APNIC
 
BitRecover OST to PST Converter Software
antoniogosling01
 
BroadLink Cloud Service introduction.pdf
DevendraDwivdi1
 
IAREUOUSTPIDWHY$)CHARACTERARERWUEEJJSKWNSND
notgachabite123
 
ChatGPT_and_Its_Uses_Presentationss.pptx
Neha Prakash
 
Clive Dickens RedTech Public Copy - Collaborate or Die
Clive Dickens
 
B M Mostofa Kamal Al-Azad [Document & Localization Expert]
Mostofa Kamal Al-Azad
 
原版一样(ANU毕业证书)澳洲澳大利亚国立大学毕业证在线购买
Taqyea
 
history of internet in nepal Class-8 (sparsha).pptx
SPARSH508080
 
Almos Entirely Correct Mixing with Apps to Voting
gapati2964
 
原版一样(ISM毕业证书)德国多特蒙德国际管理学院毕业证多少钱
taqyed
 
ChatGPT A.I. Powered Chatbot and Popularization.pdf
StanleySamson1
 

Python PCEP Multidemensional Arrays

  • 1. Module 2 Data Collections – Lists, Tuples, and Dictionaries Multidimensional arrays
  • 2. Module 2 Multidimensional arrays Lists in lists row = [] for i in range(8): row.append(WHITE_PAWN) row = [WHITE_PAWN for i in range(8)] squares = [x ** 2 for x in range(10)] #output [0, 1, 4, 9, 16, 25, 36, 49, 64, 81] twos = [2 ** i for i in range(8)] #output [1, 2, 4, 8, 16, 32, 64, 128] squares = [x ** 2 for x in range(10)] odds = [x for x in squares if x % 2 != 0 ] print(odds) #output [1, 9, 25, 49, 81]
  • 3. Module 2 Multidimensional arrays Two-dimensional arrays board = [] for i in range(8): row = [EMPTY for i in range(8)] board.append(row) EMPTY = "-" ROOK = "ROOK" board = [] for i in range(8): row = [EMPTY for i in range(8)] board.append(row) board[0][0] = ROOK board[0][7] = ROOK board[7][0] = ROOK board[7][7] = ROOK print(board) board = [[EMPTY for i in range(8)] for j in range(8)]
  • 4. Module 2 Multidimensional arrays Multidimensional nature of lists two coordinates a vertical one (row number) a horizontal one (column number) temps = [[0.0 for h in range(24)] for d in range(31)] # The matrix is magically updated here. total = 0.0 for day in temps: total += day[11] average = total / 31 print("Average temperature at noon:", average) The monthly average noon temperature
  • 5. Module 2 Multidimensional arrays Multidimensional nature of lists temps = [[0.0 for h in range(24)] for d in range(31)] # The matrix is magically updated here. highest = -100.0 for day in temps: for temp in day: if temp > highest: highest = temp print("The highest temperature was:", highest) The highest temperature
  • 6. Module 2 Multidimensional arrays Multidimensional nature of lists temps = [[0.0 for h in range(24)] for d in range(31)] # The matrix is magically updated here. hot_days = 0 for day in temps: if day[11] > 20.0: hot_days += 1 print(hot_days, "days were hot.") The days when the temperature at noon was at least 20 ℃
  • 7. Module 2 Multidimensional arrays Three-dimensional arrays • three buildings • 15 floors each • 20 rooms on each floor the type of the array's elements(True/False) calm analysis of the situation rooms = [[[False for r in range(20)] for f in range(15)] for t in range(3)] In the second building, on the tenth floor, room 14: rooms[1][9][13] = True
  • 8. Module 2 Multidimensional arrays Key takeaways 1 [expression for element in list if conditional] # A four-column/four-row table - a two dimensional array (4x4) table = [[":(", ":)", ":(", ":)"], [":)", ":(", ":)", ":)"], [":(", ":)", ":)", ":("], [":)", ":)", ":)", ":("]] print(table) print(table[0][0]) # outputs: ':(' print(table[0][3]) # outputs: ':)' list comprehension use nested lists to create matrices
  • 9. Module 2 Multidimensional arrays Key takeaways 2 # Cube - a three-dimensional array (3x3x3) cube = [[[':(', 'x', 'x'], [':)', 'x', 'x'], [':(', 'x', 'x']], [[':)', 'x', 'x'], [':(', 'x', 'x'], [':)', 'x', 'x']], [[':(', 'x', 'x'], [':)', 'x', 'x'], [':)', 'x', 'x']]] print(cube) print(cube[0][0][0]) # outputs: ':(' print(cube[2][2][0]) # outputs: ':)' create n-dimensional lists
  • 10. Congratulations! You have completed Module 2 Well done! You've reached the end of Module 2 and completed a major milestone in your Python programming education.