In Python 3, I have a list of datetime
objects that I would like, using numpy
, to wrap (python modulus %
operator) by dividing by a fixed time period represented as a python timedelta
. The goal is to derive a numpy
array containing the remainders.
Consider:
import numpy as np
from datetime import datetime,timedelta
t=[]
for i in range(10):
t.append(datetime.strptime('1066-10-1%i'%i, '%Y-%m-%d'))
delta_t = timedelta(days=2)
# Apply np.fmod(), but run into type conversion difficulties
How can I use numpy
to achieve the equivalent of the following operation?
t_mod = t % delta_t
I have tried converting to numpy
datetime64
and timedelta64
objects, so far in vain. I am happy to flesh out error messages if that would be useful, or provide any other information people may require.
Broader question: If this works for e.g. np.fmod()
, would it work for other useful numpy
functions? Is anything off-limits?
Or should I just convert everything to floats and have done with it? Or should I go via strings?
I don't want to use pandas or Python 2.