Background
In Julia programming we have a Rand function which sintaxis is :
rand([rng=GLOBAL_RNG], [S], [dims...])
which pick a random element or array of random elements from the set of values specified by S and gives an array of dimension of the third arg.
Question
I want to apply the same logic to make a simulation for an assurance policy problems:
m = 60000
n = len(policy.AGE)
k=1/10
@time begin
Death = zeros(Bool, m, n)
Accident = rand(Bernoulli(k), m, n)
Which is Julia Code, but when taking this to python i don't find the correct form of rand(Bernoulli(k), m, n)
I know to simulate a Bernoulli is just bernoulli.rvs(k,n) but the part that set of values specified by S and gives an array of dimension of the third arg.
You probably want to use size
keyword argument of rvs
:
>>> from scipy.stats import bernoulli
>>> bernoulli.rvs(0.25, size=10)
array([0, 0, 1, 0, 0, 0, 0, 0, 0, 0])