2021年3月22日星期一

Looking to change numpy array of size (m,2) to timestamps in form hh:mm AM/PM

I am having a tough time making a function that takes a numpy array of size = (m,2) and results a 12 hour format timestamp of hours and minutes. I would like to use time() from the from datetime import time library.

Knowing that

from datetime import time    timestamp = time(13,15)  print(timestamp.strftime('%I:%M %p'))  

has the output of 01:15 PM.

I'd like to take a numpy array such as (where it accounts for numbers larger than 24 as the number m as m//24

a = np.array([[0,40],[13,20],[42,20]])  

and have the result of the function function(array) be

function(a)  

with the output being a list of timestamps

[12:40 AM, 1:20 PM, 6:20 PM]  

While I'd like to use the time library from datetime, I'd be open to learning how to do this by printing strings as well.

https://stackoverflow.com/questions/66755367/looking-to-change-numpy-array-of-size-m-2-to-timestamps-in-form-hhmm-am-pm March 23, 2021 at 07:50AM

没有评论:

发表评论