python将字符串转换为整数数组

python将字符串转换为整数数组,python,arrays,numpy,string-conversion,Python,Arrays,Numpy,String Conversion,使用python,我刚刚创建了两个字符串,现在想将它们转换为整数数组 我的两根弦是地震的开始和结束时间,看起来像这样 "00:39:59.946000" "01:39:59.892652" 我想将这两个数组转换为整数数组,以便使用numpy.arange()或numpy.linspace()。预期的输出应该是一个数组,该数组在开始时间和结束时间之间具有许多等间距的值。比如说, array = [00:39:59.946000, 00:49:59.946000, 00:59:59.946000

使用python,我刚刚创建了两个字符串,现在想将它们转换为整数数组

我的两根弦是地震的开始和结束时间,看起来像这样

"00:39:59.946000"

"01:39:59.892652"
我想将这两个数组转换为整数数组,以便使用
numpy.arange()
numpy.linspace()
。预期的输出应该是一个数组,该数组在开始时间和结束时间之间具有许多等间距的值。比如说,

array = [00:39:59.946000, 00:49:59.946000, 00:59:59.946000, 01:09:59.946000, etc...]

然后,我想使用这个数组的值作为图形x轴上的每个增量。如果您有任何建议/帮助,我们将不胜感激。

您能将时间戳转换为历元时间吗?

既然您的字符串表示时间数据,请看一看

>>> [int(x) for x in eq_time if x.isdigit()]
>>> import time
>>> t1="00:39:59.946000"
>>> t2=time.strptime(t1.split('.')[0]+':2013', '%H:%M:%S:%Y') #You probably want year as well.
>>> time.mktime(t2) #Notice that the decimal parts are gone, we need to add it back
1357018799.0
>>> time.mktime(t2)+float('.'+t1.split('.')[1]) #(add ms)
1357018799.946

#put things together:
>>> def str_time_to_float(in_str):
    return time.mktime(time.strptime(in_str.split('.')[0]+':2013', '%H:%M:%S:%Y'))\
           ++float('.'+in_str.split('.')[1])
>>> str_time_to_float("01:39:59.892652")
1357022399.892652
类似于

from datetime import datetime                                                                                                                                                                                                                                                      

t1 = datetime.strptime("2013:00:39:59.946000", "%Y:%H:%M:%S.%f")                                                                               
t2 = datetime.strptime("2013:01:39:59.892652", "%Y:%H:%M:%S.%f")

预期输出是什么?上述的预期输出应该是一个数组,该数组在开始时间和结束时间之间有一个等距的数值。例如,array=[00:39:59.946000,00:49:59.946000,00:59:59.946000,01:09:59.946000,等等…]然后我想使用这个数组的值作为图表x轴上的每个增量。请更新你的问题,而不是评论。嗯……我不想打断你,但是
00:39:59.946000
不是
int
。你到底想要什么?@inspectorG4dget我想这里的答案是
datetime
,但那只是我。你的意思是
isdigit()
?试试datetime的版本。据此编辑。