How can I generate n random values from a bimodal distribution in Python?

ej wm

I tried generating and combining two unimodal distributions but think there's something wrong in my code.

N=400
mu, sigma = 100, 5
mu2, sigma2 = 10, 40
X1 = np.random.normal(mu, sigma, N)
X2 = np.random.normal(mu2, sigma2, N)
w = np.random.normal(0.5, 1, N)
X = w*X1 + (1-w)*X2
X = X.reshape(-1,2)

When I plot X I don't get a bimodal distribution

0 0

It's unclear where your problem is; it's also unclear what the purpose of the variable w is, and it's unclear how you judge you get an incorrect result, since we don't see the plot code, or any other code to confirm or reject a binomial distribution.
That is, your example is too incomplete to exactly answer your question. But I can make an educated guess.

If I do the following below:

import numpy as np
import matplotlib.pyplot as plt

N=400
mu, sigma = 100, 5
mu2, sigma2 = 10, 40
X1 = np.random.normal(mu, sigma, N)
X2 = np.random.normal(mu2, sigma2, N)
X = np.concatenate([X1, X2])
plt.hist(X)

and that yields the following figure:

histogram of X

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How can I generate a matrix with random values based from a larger matrix in Python?

How to generate n random numbers from negative binomial distribution?

How to generate random values from a string in python?

Generate random numbers from lognormal distribution in python

how do you generate random numbers from a bimodal Gaussian Probability Density Function in MATLAB?

how can i get a random sample from dataframe but have it contain a distribution of a variable? PYTHON

How to generate n random numbers from a normal distribution using random-fu (Haskell)?

How can I generate a random number for each group of values in a column in Python?

How can I generate different random values in Haskell?

How can I generate random (int) values with specific size and mean?

How to generate random uniform distribution by selecting h/l values from multiple arrays?

How to simulate a bimodal distribution in javascript?

How can I generate list of random odd numbers from 1 to 99 (including) in python

Generate random bytearray from a distribution

How can I generate n random numbers without a for loop

How can i generate random char from variable

How can I generate a random sequence of elements from a list in Haskell?

generate N random numbers from a skew normal distribution using numpy

Generating N random data sets from a sample of n values following a normal distribution? (Python)

How can I generate a random hex color code using python?

Generate random numbers from exponential distribution and model using python

Generate Random Number in Range from Single-Tailed Distribution with Python

Generate random numbers from a distribution given by a list of numbers in python

How do I generate discrete random events with a Poisson distribution?

How can i generate random variables using np.random.zipf for a given range of values?

How can we generate random values in Scrypto?

How to generate random categorical data in python according to a probability distribution?

How do I select a random key from a hash using the probability distribution stored within the corresponding values?

How to generate N random values with SELECT?