I am learning python so please bear with me. I have been trying to get a datetime variable into a numpy array, but have not been able to figure out how. I need to calculate differences between times for each index later on, so I didn't know if I should put the datetime variable into the array, or convert it to another data type. I get the error:
'NoneType' object does not support item assignment
Is my dtype variable constructed correctly? This says nothing about datetime type.
import numpy as np
from liblas import file
f = file.File(project_file, mode = 'r')
num_points = int(f.__len())
# dtype should be [float, float, float, int, int, datetime]
dt = [('x', 'f4'), ('y', 'f4'), ('z', 'f4'), ('i', 'u2'), ('c', 'u1'), ('time', 'datetime64')]
xyzict = np.empty(shape=(num_points, 6), dtype = dt)
# Load all points into numpy array
counter = 0
for p in f:
newrow = [p.x, p.y, p.z, p.i, p.c, p.time]
xyzict[counter] = newrow
counter += 1
Thanks in advance
EDIT: I should note that I plan on sorting the array by date before proceeding.
p.time is in the following format:
>>>p.time
datetime.datetime(1971, 6, 26, 19, 37, 12, 713269)
>>>str(p.time)
'1971-06-26 19:37:12.713275'