vendredi 12 mars 2021

Generating random number sequentially (X1,X2,X3) with uniform distribution in python

I need to generate X1,X2 and X3 as follows:

  1. Sample X1 ~ U(0, 1)
  2. Sample X2 ~ U(0, 1-X1)
  3. Set X3 = 1- X1- X2.

I am trying to code as:

N = 100
    
X1 = np.random.rand(N)
X2 = X1 - np.random.rand(N)
X3 = 1-X1-X2

But it's returning -(ve) value for X2. How can I get (+)ve values along according to the condition.

Thanks




Aucun commentaire:

Enregistrer un commentaire