I\'m looking for a function analogous to np.interp that can work with datetime objects.
For example:
import datetime, numpy
You can convert them to timestamps (edited to reflect the use of calendar.timegm to avoid timezone-related pitfalls).
# Python 2.7
import datetime, numpy as np
import calendar
def toTimestamp(d):
return calendar.timegm(d.timetuple())
arr1 = np.array([toTimestamp(datetime.datetime(2008,1,d)) for d in range(1,10)])
arr2 = np.arange(1,10)
result = np.interp(toTimestamp(datetime.datetime(2008,1,5,12)),arr1,arr2)
print result # Prints 5.5