ValueError: sample is larger than sample by sample from graph
I am trying to randomly select n samples from a graph. To do this, I create a list named X using the random.sample function as shown below:
X= random.sample(range(graph.ecount()), numPosSamples)
The problem is, when numPosSamples is graph.ecount (), I get the following error:
ValueError: Sample larger than population
Any help would be much appreciated. Thanks to
source to share
I'm not sure how it numPosSamples
gets its value, but since it random.sample
is fetching without replacing, what is probably happening here is that there are numPosSamples
more than the number of edges in your graph. As a result, Python creates the ValueError
one you see.
Either reduce the number of samples to the number of edges, or use a sampling technique that allows you to perform select and replace, such as a list comprehension with random.choice
.
source to share