Skip to content
Advertisement

elegant way of convert a numpy array containing datetime.timedelta into seconds in python 2.7

I have a numpy array called dt. Each element is of type datetime.timedelta. For example:

JavaScript

how can I convert dt into the array dt_sec which contains only seconds without looping? my current solution (which works, but I don’t like it) is:

JavaScript

I tried to use dt.total_seconds() but of course it didn’t work. any idea on how to avoid this loop?

Thanks

Advertisement

Answer

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement