python与matlab速度谁快_Python与MATLAB算法性能比较

我有一个关于代码性能的问题。一个用python实现,一个用MATLAB实现。代码计算时间序列的样本熵(听起来很复杂,但基本上是一堆for循环)。在

我在相对较大的时间序列上运行这两个实现(大约95k+个样本),具体取决于时间序列。MATLAB实现在45秒到1分钟内完成计算。python实现基本上永远不会完成。我把tqdm放到python for循环上,上面的循环仅以~1.85s/it的速度移动,估计完成时间超过50小时(我让它运行了15分钟以上,迭代次数相当一致)。在

输入和运行时示例:

MATLAB(约52秒):a = rand(1, 95000)

sampenc(a, 4, 0.1 * std(a))

Python(目前5分钟,预计49小时):

^{pr2}$

Python实现:# https://github.com/nikdon/pyEntropy

def sample_entropy(time_series, sample_length, tolerance=None):

"""Calculate and return Sample Entropy of the given time series.

Distance between two vectors defined as Euclidean distance and can

be changed in future releases

Args:

time_series: Vector or string of the sample data

sample_length: Number of sequential points of the

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值