是否有一种Python等价于MATLAB';时间';功能?
我正在将MatlabR2011B代码移植到Python 3.5.1。 大约10年前编写的原始MATLAB代码包含一个“时间”函数,如下所示:是否有一种Python等价于MATLAB';时间';功能?,python,matlab,time,Python,Matlab,Time,我正在将MatlabR2011B代码移植到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 fsamp
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”太笼统了,很难在谷歌上搜索。)这个“time”函数似乎返回1000/fsample(例如,如果fsample=10000,则返回0.1)乘以索引“x”。有人知道Python中类似的函数吗
。。。请注意,此“时间”函数与MATLAB R2014b中引入的“时间”函数不同:
[它应该足够简单,可以实现类似的功能 用于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))]
它应该足够简单,可以实现类似的功能 用于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))]
如果你从matlab移植-你是否使用过任何库,如numpy、scipy或pandas?是的,numpy和scipy。我还从未使用过pandas。如果我正确地理解了你的示例-我想你不是100%确定…如果你从matlab移植-你是否使用过任何库,如numpy、scipy或pandas?是的,numpy和西皮。我还从来没有用过熊猫。如果我正确理解了你的例子——我想你不是100%确定……很高兴听到:)很高兴听到:)