I have a numpy array of shape (1e6, 1) that I would like to take weighted samples from based on the values that are largest. However, it is difficult to scale the list to sum to one b/c of the accuracy required for floating point numbers.
Here is an example I can create by using random numbers(in my case the numbers are not random)
import numpy as np
A = np.random.rand(1000000)
probs = A / np.sum(A)
sample = np.random.choice(A, p=probs)
# fails b/c probs don't sum to one