【问题标题】:How to convert matlab function to python - finiterv如何将 matlab 函数转换为 python -finiterv
【发布时间】:2022-11-09 22:50:10
【问题描述】:

这是我试图从 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));`

这是我的python代码:

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,))`

我收到一条错误消息 - uniform() 缺少 1 个必需的位置参数:'b'

我想我没有正确转换随机统一函数!

【问题讨论】:

  • 不应该是r=random.uniform(m,1)吗?

标签: python matlab random


【解决方案1】:

r=random.uniform((m,1)) 更改为r=random.uniform(m,1)

按照您编写的方式,您将一个参数(它是一个元组)传递给 uniform 函数,但它需要两个单独的数字。

【讨论】:

    猜你喜欢
    • 2014-03-05
    • 1970-01-01
    • 1970-01-01
    • 2013-05-13
    • 2016-11-07
    • 1970-01-01
    • 2020-02-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多