Question: Part 1 is correct. I need help with part 2 because the code I have for num_options is returning an incorrect value. Connections between airports

Part 1 is correct. I need help with part 2 because the code I have for num_options is returning an incorrect value.

Part 1 is correct. I need help with part 2 because the

Connections between airports can be modelled by a graph. The nodes represent airports, and the edges represent nonstop flight routes between the airports. Two nodes are connected by a edge if there is a nonstop flight between the two airports; for simplicity, we assume that if there is a nonstop flight from one airport to another, there is a returning nonstop flight so that the graph is undirected. The matrix nonstop_flights represents a network of 100 U.S. airports as described above. We ask you to determine the number of distinct routes to fly from O'Hare Airport (ORD) to Los Angeles International Airport (LAX) with at most one layover (that is, either nonstop or with exactly one layover). 1) Compute a 100100-matrix A such that the entry in the i-th row and the j-th column of A is the number of walks from node j to node i of length at most 2. Store this matrix as atmost_1_layover. 2) Assuming that ORD is airport \# 48 (the 49th row/column of the adjacency matrix when one-indexing) and LAX is airport \# 47 (the 48th row/column of the adjacency matrix when one-indexing). Compute the number of distict routes to fly from ORD to LAX with at most one layover. Save this as num_options. The setup code gives the following variables: Your code snippet should define the following variables: user_code.py import nunpy as np import nunpy. Iinalg as 1 a atmost_1_layover = nonstop_flights g nonstop_flights + nonstop_flights num_options = np.sum(atmost_1_1ayover [48, [49] + _ist(np.where(nonstop_flights [48, :] > ) [0] ) ] )

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!