lundi 25 avril 2016

Matlab to Python conversion of rand()

In Matlab I have the following:

duration = 20
n=5
times = rand(1,n)*duration;

The variable "times" gives a 1-by-n matrix, which is populated with random numbers between 0 and 1, then multiplied by 20. This will result in a set of 5 numbers between 0 and 20.

Now I want to achieve the same in Python, what would be the equivalent? I tried the following:

times = random.uniform(1,durations,n)  %% or times = random.uniform(1,20,5)

But I get this error:

TypeError: uniform() takes exactly 3 arguments (4 given)

which does not make sense to me, because I only seem to have given it 3 arguments.




Aucun commentaire:

Enregistrer un commentaire