0
我很难将numpy数据类型timedelta64乘上浮点数。Python:timedelta64类型与浮点数的划分和乘法运算
对于我需要用开普勒第二定律计算恒星周期的任务。有很多数据点的,所以我想Python来计算两个位置之间的区域和时段划分它,使用下面的代码:
D = data['data']
vect = D-c #Data point minus center of ellipse
date = data['time'] #time for data point in np.timedelta64
Area_tot = np.pi*np.sqrt(chi[0])*np.sqrt(chi[1]) #total area of ellipse
P = np.array([])
for i in range(1,len(D[0])):
Area = LA.norm(np.cross(vect[i],vect[i-1]))/2 #usie cross product to calculate area
Time = date[i]-date[i-1]
P = np.append(P,(Area_tot/Area)*Time)
如果这样做,但是,我得到以下错误:
TypeError: ufunc 'multiply' not supported for the input types, and the inputs could
not be safely coerced to any supported types according to the casting rule 'safe'
所以,我想知道我怎么能倍增timedelta64数据类型与浮...
在此先感谢和温柔,我很新的这两个计算器和编程:)
timedelta64数据类型似乎没有total_seconds() – Corollary 2012-03-31 16:12:25
.tolist()为您提供了一个datetime.timedelta对象,它具有.total_seconds()。如果您不想使用datetime.timedelta,则[timedelta64] .astype('float')会以微秒为单位给出差异。 – 2012-03-31 16:30:52
谢谢!我会尝试那个。 – Corollary 2012-03-31 16:34:30