Simulating Random Matlab Process in Python Issue
I'm trying to simulate a Bernoulli Resolution Process in Python. I have a
Matlab example of it. Regardless of the jargon, I produce a column vector
of 0's and 1's depending on some random variables.
num_trials = 1
b_energy_res = zeros(num_photon,num_trials);
for idx = 1:num_trials
energy_trial = randn(1,1)*energy_sigma+3*energy_sigma;
b_energy_res(:,idx) = rand(num_photons,1)>energy_trial;
end;
t = t+(1-b_energy_res)*1e9;
t = t/1e-12;
It will output some vector with 0's and 1's.
I try to do the same with Python, but I get errors. Also, I'm trying to
have it so that the array in numpy has about the same frequency of values
of 1 and 0. I could do a histogram to check them both. I get attribute
errors:
b_energy_res = np.zeros(num_photon)
energy_trial = np.random.standard_normal() * energy_sigma + 3 * energy_sigma
r = np.random.uniform(0.0,1.0,num_photon)
for i in xrange(int(num_photon)):
if r[i] > energy_trial[i]:
b_energy_res[i] = 1
t = t + (1-b_energy_res)*1e9
t = t*1e12
The error is: 'float' has no attribute getitem
Also, is this producing what I want it to be?
No comments:
Post a Comment