samedi 29 octobre 2022

How to convert matlab function to python - finiterv

Here is the code I am trying to convert from matlab

function x=finiterv(s,p,m)
% returns m samples
% of finite (s,p) rv
%s=s(:);p=p(:);
r=rand(m,1);
cdf=cumsum(p);
x=s(1+count(cdf,r));`

and here is my python code:

def infinterv(s,p,m):
#return m samples
#of finite (s,p) rv
r=random.uniform((m,1))
cdf=p.cumsum(axis=0)
x=s(1+count(cdf,))`

I get an error saying - uniform() missing 1 required positional argument: 'b'

I think I am not converting the random uniform function correctly!




Aucun commentaire:

Enregistrer un commentaire