Reputation: 13
I am having difficulties multiplying the numpy datatype timedelta64 with floats.
For a task i need to calculate the period of a star using Kepler's second law. There are a lot of data points, so I want python to calculate the area between 2 positions and divide it by the period, using following code:
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)
When doing this, however, I get the following error:
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'
So, I am wondering how I can multiply the timedelta64 datatype with a float...
Thanks in advance and be gentle, I am quite new to both stackoverflow and programming :)
Upvotes: 0
Views: 1116
Reputation: 44614
Time.tolist().total_seconds()
gets the difference as a float.
Upvotes: 1