Computer Networking: A Top-Down Approach (7th Edition)
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN: 9780133594140
Author: James Kurose, Keith Ross
Publisher: PEARSON
Bartleby Related Questions Icon

Related questions

Question
100%
Computing in python plz help with matrices
Q6 - Matrices 3
Create a double for loop that goes through a randomly generated matrix and counts (and prints) the number of threes that appear in the matrix. This code
samples from a uniform distribution so think about how many threes you would expect to see.
Optional (not for marks): Another way to count these (as long as your matrix is a NumPy matrix) would be (randMat == 3).sum(). If you're curious about
how that works, try generating a smaller matrix like smallMat = np.random.randint(1, 11, size = (10, 10)) and then smallMat == 3 to see what
you get. You might be surprised that summing the result matrix works, but in Python True is equivalent to 1 in many cases and False equivalent to 0.
There are often these sorts of 'terse' codes which can greatly reduce the typing required to achieve a result. In some cases, they can also be faster. However,
for now we mostly want to emphasize how to use the for loop to loop through the matrix.
H randMat = np.random.randint(1, 101, size = (100, 100))
for loop(for loop)
n[]:
n [139]:
import numpy as np
randMat = np.random.randint(1, 101, size = (100, 100))
for i in range(len(randMat)):
print (i)
1.
2
4
5:38 PM
ENG
-18°C Mostly cloudy
2022-01-2
search
expand button
Transcribed Image Text:Q6 - Matrices 3 Create a double for loop that goes through a randomly generated matrix and counts (and prints) the number of threes that appear in the matrix. This code samples from a uniform distribution so think about how many threes you would expect to see. Optional (not for marks): Another way to count these (as long as your matrix is a NumPy matrix) would be (randMat == 3).sum(). If you're curious about how that works, try generating a smaller matrix like smallMat = np.random.randint(1, 11, size = (10, 10)) and then smallMat == 3 to see what you get. You might be surprised that summing the result matrix works, but in Python True is equivalent to 1 in many cases and False equivalent to 0. There are often these sorts of 'terse' codes which can greatly reduce the typing required to achieve a result. In some cases, they can also be faster. However, for now we mostly want to emphasize how to use the for loop to loop through the matrix. H randMat = np.random.randint(1, 101, size = (100, 100)) for loop(for loop) n[]: n [139]: import numpy as np randMat = np.random.randint(1, 101, size = (100, 100)) for i in range(len(randMat)): print (i) 1. 2 4 5:38 PM ENG -18°C Mostly cloudy 2022-01-2 search
Expert Solution
Check Mark
Knowledge Booster
Background pattern image
Recommended textbooks for you
Text book image
Computer Networking: A Top-Down Approach (7th Edi...
Computer Engineering
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:PEARSON
Text book image
Computer Organization and Design MIPS Edition, Fi...
Computer Engineering
ISBN:9780124077263
Author:David A. Patterson, John L. Hennessy
Publisher:Elsevier Science
Text book image
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:9781337569330
Author:Jill West, Tamara Dean, Jean Andrews
Publisher:Cengage Learning
Text book image
Concepts of Database Management
Computer Engineering
ISBN:9781337093422
Author:Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:Cengage Learning
Text book image
Prelude to Programming
Computer Engineering
ISBN:9780133750423
Author:VENIT, Stewart
Publisher:Pearson Education
Text book image
Sc Business Data Communications and Networking, T...
Computer Engineering
ISBN:9781119368830
Author:FITZGERALD
Publisher:WILEY