I have a numpy array of datetime64
, and I would like to round off the sub-second values of the array elements. E.g., from 2001-1-1 10:33:32.5
to 2001-1-1 10:33:32.0
. I am looking for a vecotrized method.
More generally, I am looking for a vectorized method to round to any frequency (minutes, days, etc.).
rounded = numpy.array(myarray, dtype='datetime64[s]')
or
rounded = myarray.astype('datetime64[s]')
This also works for minutes by using:
rounded = numpy.array(myarray, dtype='datetime64[m]')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With