Я бы все равно использовал np.random.choice()
.Решите первую проблему, попросив np.random.choice()
выбрать index пути, а не сам путь.Решите вторую проблему, масштабируя веса таким образом, чтобы они составляли 1.
import numpy as np
a, b, c, d = 1, 2, 3, 4
population = [
[[a, b, c, d], [10.12]],
[[b, c, a, d], [11.33]],
[[d, a, c, b], [11.5]],
[[b, a, d, c], [12.07]]
]
# Build probability array
bias_weights = [x / len(population) for x in range(len(population))]
prob = np.array(bias_weights) / np.sum(bias_weights)
# Get random integers between 0 and len(prob)-1, drawn according to prob
sample_size = 2
choice_indices = np.random.choice(len(prob), size=sample_size, replace=False, p=prob)
# Get corresponding paths
paths = [population[i][0] for i in choice_indices]