Question: # TODO: Implement the function. The function is partially implemented below. def get _ average _ path _ length ( g , n _ samples
# TODO: Implement the function. The function is partially implemented below.
def getaveragepathlengthg nsamples:
Get the average path length between two random nodes.
# Pick two random distinct node pairs
nnodes gvcount
while True:
src nprandom.choicennodes, nsamples
trg nprandom.choicennodes, nsamples
# If all the two nodes are distinct
# We do not want to have two nodes to be the same node, which results in the path length of leading to the underestimation of the average path length
if npallsrc trg:
break
# Compute the average shortest path length between the sampled nodes
pathlengths
# Return the average path length
return npmeanpathlengths
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
