我正在尝试将XML
文件读入NumPy
记录数组。时间是祖鲁时间,u'2013-06-06T17:47:38Z'
,其他列是floats
。
时间和时间floats
都可以转换为NumPy
数组。但是,如果我尝试制作 a recordarray
,它会以多种方式失败(这可能表明我不知道如何创建记录数组):
In [124]: dataarr = np.array(zip(*[datadict[k] for k in keys]),
.....: dtype=[(k,dtypes[k]) for k in keys])
Traceback (most recent call last):
File "<ipython-input-124-d59123796cfa>", line 2, in <module>
dtype=[(k,dtypes[k]) for k in keys])
ValueError: Cannot create a NumPy datetime other than NaT with generic units
In [125]: dataarr = np.array([datadict[k] for k in keys],
dtype=[(k,dtypes[k]) for k in keys])
Traceback (most recent call last):
File "<ipython-input-125-ee9077bf1961>", line 2, in <module>
dtype=[(k,dtypes[k]) for k in keys])
TypeError: expected a readable buffer object
In [126]: dataarr = np.array([datadict[k] for k in keys],
dtype=[dtypes[k] for k in keys])
Traceback (most recent call last):
File "<ipython-input-126-a456052bdfd4>", line 2, in <module>
dtype=[dtypes[k] for k in keys])
TypeError: data type not understood
In [127]: dtypes
Out[127]: {'altitude': 'float', 'distance': 'float', 'time': 'datetime64'}
创建recordarray
包含时间的正确方法是什么?
(keys
是一个列表,datadict
是dtype
字典)