我无法使用 datetime64 类型创建记录数组。我正在运行 Python 2.7、Numpy 1.7。
这是一个最小的例子:
p_dtype = np.dtype({"names": ['trns_id', 'trns_date', 'qty', 'price', 'amount', 'description', 'commission', 'fees'],
"formats": [long, "M8", float, float, float, "S40", float, float]})
p_row = (8609132959, np.datetime64('2012-05-01'), 337.574, 4.86, -1640.61, 'Bought 337.574 XYZ @ 4.86', 0.0, 0.0)
print p_list, p_dtype
p_array = np.array(p_row, dtype=p_dtype)
我收到以下错误(和输出):
TypeError Traceback (most recent call last)
<ipython-input-137-0b4de45b819c> in <module>()
6 print p_list, p_dtype
7
----> 8 p_array = np.array(p_row, dtype=p_dtype)
9
10 print "Array: %s, dtype: %s" % (p_array, p_array.dtype)
TypeError: Cannot cast NumPy timedelta64 scalar from metadata [D] to according to the rule 'same_kind'
(8609132959.0, numpy.datetime64('2012-05-01'), 337.574, 4.86, -1640.61, 'Bought 337.574 PIMSX @ 4.86', 0.0, 0.0) [('trns_id', '<i8'), ('trns_date', '<M8'), ('qty', '<f8'), ('price', '<f8'), ('amount', '<f8'), ('description', 'S40'), ('commission', '<f8'), ('fees', '<f8')]
提示,有人吗?