<div dir="ltr">I just noticed that there is no obvious way to convert a timedelta64 to seconds (or some other easy unit) as a number.<div><br></div><div>The stdlib datetime.datetime has a .total_seconds() method for doing that. I think it's a handy thing to have.</div><div><br></div><div>Looking at StackOverflow (and others), I see people suggesting things like:</div><div><br></div><div><font face="monospace">a_timedelta.astype(np.float) / 1e6</font></div><div><br></div><div>This seems a really bad idea, as it's assuming the timedelta is storing milliseconds.</div><div><br></div><div>The "proper" way to do it also suggested:</div><div><br></div><font face="monospace">a_timedelta / np.timedelta64(1, 's')</font>





<div><br clear="all"><div>This is, in fact, a much better way to do it, and allows you to specify other units if you like: "ms"., "us", etc.</div><div><br></div><div>There was semi-recently a discussion thread on python-ideas about adding other methods to datetime: (e.g.  <font face="monospace">.total_hours, .total_minutes)</font>. That was pretty much rejected (or petered out anyway), and some argued that dividing by a timedelta of the unit you want is the "right" way to do it anyway (some argued that .total_seconds() never should have been added.<br></div><div><br></div><div>Personally I understand the "correctness" of using united-division, but "practicality beats purity", and the discoverability of a method or two really makes it easier on folks.</div><div><br></div><div>That being said, of folks don't want to add .total_seconds and the like -- we should add a bit to the docs about this, suggesting using the division approach.</div><div><br></div><div>-CHB</div><div><br></div><div><br></div>-- <br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><br>Christopher Barker, Ph.D.<br>Oceanographer<br><br>Emergency Response Division<br>NOAA/NOS/OR&R            (206) 526-6959   voice<br>7600 Sand Point Way NE   (206) 526-6329   fax<br>Seattle, WA  98115       (206) 526-6317   main reception<br><br><a href="mailto:Chris.Barker@noaa.gov" target="_blank">Chris.Barker@noaa.gov</a></div></div></div>