probability

How do I distribute a value between numbers in a list

How do I distribute a value between numbers in a list Question: I am creating a bias dice rolling simulator I want the user to: 1.Input the number they would like to change the prob of 2.Input the prob (in decimal form) Then I would like my program to distribute the remainder between the other …

Total answers: 2

Check if random variables are independent Python

Check if random variables are independent Python Question: Given a table below X Y pr 0 1 0.30 0 2 0.25 1 1 0.15 1 2 0.30 I intended to create a function to check the independence between the two variables X and Y. Note that the third column pr in the table is probability. …

Total answers: 2

How to compute 2D cumulative sum efficiently

How to compute 2D cumulative sum efficiently Question: Given a two-dimensional numerical array X of shape (m,n), I would like to compute an array Y of the same shape, where Y[i,j] is the cumulative sum of X[i_,j_] for 0<=i_<=i, 0<=j_<=j. If X describes a 2D probability distribution, Y could be thought of as the 2D …

Total answers: 1

Variable length element sampling from list based on weights

Variable length element sampling from list based on weights Question: I want to select some items from a list depending on a given weight for each element. The length of the output is not known. This needs to be done a lot of times. So, say I have a list of [id, probability] like [[1, …

Total answers: 1

random.choice for 2D array, bigger numbers with higher probability?

random.choice for 2D array, bigger numbers with higher probability? Question: Is there a way to randomly pick n-items from every row in a 2D array with the higher probability picking the bigger values w/o using a LOOP random.choice() works only for 1D array… F.e. if i have : q = np.random.random((10,10)) i can pick the …

Total answers: 2

Creating a probability distribution using Numpy in Python3.6

Creating a probability distribution using Numpy in Python3.6 Question: I’m trying to create a probability distribution using Numpy in the following way: x = 3 pat = [0.20, 0.30, 1.30] z = numpy.random.choice(x, p=numpy.ndarray.tolist(numpy.array(pat)/sum(pat))) And this works fine. The problem is that my “population” is evolving and starts at 0, meaning that this may happen: …

Total answers: 3

Scipy Multivariate Normal: How to draw deterministic samples?

Scipy Multivariate Normal: How to draw deterministic samples? Question: I am using Scipy.stats.multivariate_normal to draw samples from a multivariate normal distribution. Like this: from scipy.stats import multivariate_normal # Assume we have means and covs mn = multivariate_normal(mean = means, cov = covs) # Generate some samples samples = mn.rvs() The samples are different at every …

Total answers: 1

Matplotlib graphing distribution with two colors

Matplotlib graphing distribution with two colors Question: The goal here is to color value above a certain threshold into one color and values below this threshold into another color. The code below tries to just separate it into two histographs but it only looks balanced if the threshold is at 50%. I’m assuming I must …

Total answers: 3

convert an unfair coin into a fair coin in Python 2.7

convert an unfair coin into a fair coin in Python 2.7 Question: Using Python 2.7. Suppose I have an unfair coin and I want to turn it into a fair coin using the following way, Probability of generating head is equal for unfair coin; Flip unfair coin and only accept head; When a head is …

Total answers: 2