[英]Is there a Python equivalent to MATLAB 'time' function?
我正在将MATLAB R2011b代码移植到Python 3.5.1。 大约10年前编写的原始MATLAB代码包含以下“时间”函数:
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中找不到任何等效函数。 (函数名称“时间”太笼统,很难在Google上搜索。)看来,此“时间”函数返回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]
实现类似功能应该足够简单。
对于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))]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.