Home > Software engineering >  Converting MATLAB random function to python
Converting MATLAB random function to python

Time:07-26

My task is to convert one big MATLAB file into python.

There is a line in MATLAB

weightsEI_slow = random('binom',1,0.2,[EneuronNum_slow,IneuronNum_slow]);      

I am trying to convert this into python code, I am not quite finding the right documentation. I looked for numpy library too. Does any one have any suggestions?

CodePudding user response:

It looks like you generate a random number that follows the Binomial distribution with probability p=0.2 and sample size n=1. In turn, you can leverage numpy

import numpy as np

np.random.binomial(n=1, p=0.2)
>0

If you require replicability, add np.random.seed(3408) before the number is sampled. Otherwise, the output might be 0 or 1 depending on the execution. Of course, you can switch in another integer value as the seed instead of 3408.

  • Related