有一个Python等价于MATLAB的'time'函数吗?

2024-04-20 03:48:19 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在将MatlabR2011B代码移植到Python3.5.1。 大约10年前编写的原始MATLAB代码包含一个“time”函数,如下所示:

t_x=time(x,fsample);

输出为:

debug> x
x =

  -0.067000  -0.067000  -0.068000  -0.069000  -0.069000  -0.070000  -0.070000  -0.071000  -0.071000  -0.072000

debug> fsample
fsample =  10000

debug> t_x
t_x =

    0.00000    0.10000    0.20000    0.30000    0.40000    0.50000    0.60000    0.70000    0.80000    0.90000

我想在Python中做同样的事情,但是在Python中找不到任何等价的函数。(函数名'time'太笼统了,很难在Google上搜索。)似乎这个'time'函数返回1000/fsample(例如,如果fsample=10000,则返回0.1)乘以索引'x'。有人知道Python中类似的函数吗?你知道吗

。。。请注意,此“时间”函数与MATLAB R2014b中引入的“时间”函数不同: [http://www.mathworks.com/help/matlab/ref/time.html?searchHighlight=time&s_tid=gn_loc_drop][1]


Tags: 函数代码debughttptimewwwgoogle时间
1条回答
网友
1楼 · 发布于 2024-04-20 03:48:19

它应该足够简单,可以实现类似的功能。你知道吗

对于numpy数组

import numpy as np
def time(x, fsample):
    return np.linspace(0, (1000/fsample)*(len(x) - 1), num=len(x))

对于简单的python列表

def time(x, fsample):
    return [i*(1000/fsample) for i in range(len(x))]

相关问题 更多 >