I have this number: 19576.4125
. I want to save it inside a Numpy array, and I think that while the bit count is lower, it is still better. Is this right?
I tried to save inside a half and a single, but I don't know why it changes the number.
- My number:
19576.4125
- Half:
19580.0
- single:
19576.412
This number is generated by a method that I created to make a datetime
go to a float number. I can use timestamp, but I don't need the seconds and milliseconds, so I tried to create my own method that saves only date, hours and minutes. (My database doesn't accept datetime
s and timedelta
s).
This is my generator method:
from datetime import datetime
def get_timestamp() -> float:
now = datetime.now()
now.replace(microsecond=0, second=0)
_1970 = datetime(1970, 1, 1, 0, 0, 0)
td = now - _1970
days = td.days
hours, remainder = divmod(td.seconds, 3600)
minutes, second = divmod(remainder, 60)
timestamp = days + hours / 24 + minutes / 1440
return round(timestamp, 4)
How I'm creating the array:
from numpy import array, half, single
__td = get_timestamp()
print(__td)
__array = array([__td], dtype=half)
print(type(__array[0]))
print(__array[0])
__array = array([__td], dtype=single)
print(type(__array[0]))
print(__array[0])
EDITED 08/07 11h02 AM
Hello, such the comments said, I think that this number can't be saved in a half or single type. So how I save this number with better performance? Is better save then like a int and multiply by 10000, a float64 or string?
And not, I don't want a better way to sabe datetime
s I want a better way to save this float number with better performance. But thank you for te other replies.