这是未来的警告,而不是错误。更改已推迟到1点16分。它与多字段索引有关,你的
[['X','Y','Z']]
步骤。
In [56]: dt = np.dtype([('ID', '<i8'), ('X', '<f8'), ('Y', '<f8'), ('Z', '<f8'), ('FREQ', '<i8')])
In [57]: arr = np.ones(3, dtype=dt)
In [58]: arr
Out[58]:
array([(1, 1., 1., 1., 1), (1, 1., 1., 1., 1), (1, 1., 1., 1., 1)],
dtype=[('ID', '<i8'), ('X', '<f8'), ('Y', '<f8'), ('Z', '<f8'), ('FREQ', '<i8')])
当你只看田野时,它是安静的:
In [59]: arr[['X','Y','Z']]
Out[59]:
array([(1., 1., 1.), (1., 1., 1.), (1., 1., 1.)],
dtype=[('X', '<f8'), ('Y', '<f8'), ('Z', '<f8')])
但是当你试图用它们做些什么的时候,它会发出改变的警告。注意,它仍然执行操作。
In [60]: arr[['X','Y','Z']].view('float64')
/usr/local/bin/ipython3:1: FutureWarning: Numpy has detected that you may be viewing or writing to an array returned by selecting multiple fields in a structured array.
This code may break in numpy 1.16 because this will return a view instead of a copy -- see release notes for details.
Out[60]: array([1., 1., 1., 1., 1., 1., 1., 1., 1.])
消除警告的一种方法是添加
copy()
索引后:
In [62]: arr[['X','Y','Z']].copy().view('float64')
Out[62]: array([1., 1., 1., 1., 1., 1., 1., 1., 1.])
view
换工作。但在计划的改变中
arr[['X','Y','Z']]
数据布局会有所不同
看法