-
Notifications
You must be signed in to change notification settings - Fork 3
Python
Julie edited this page Jun 13, 2019
·
15 revisions
The Python script can be used as follows to create M sets each containing N random values that sum up to 1.0:
import numpy as np
# make sure we get for this example reproducible results
np.random.seed(seed=12345)
M = 3 # number of random number sets
N = 5 # number of random numbers that need to sum up to C
# matrix of random sets (# rows = M, # of columns = N)
rand = PieShareDistribution(M, N, remainder=True)The matrix contains M=3 sets each containing N=5 values:
rand[0,:] # [ 1.45478257 0.18399595 0.13153194 0.25154563 0.9781439 ]
rand[1,:] # [ 0.60757194 1.60624723 0.32318579 0.34674005 0.11625498]
rand[2,:] # [ 0.87384856 1.40702379 0.00302248 0.07622537 0.63987979]They all sum up to 1.0:
np.sum(rand[:,:],axis=1) # [ 1. 1. 1.]
© 2019-2021 - PieShareDistribution - juliane.mai@uwaterloo.ca
Funded under IMPC project of Global Water Futures program.
Table of contents