我有一个这样的记录数组
============ rec_data
<type 'numpy.ndarray'>
[(269.05515748,24.71801578) (276.96505874,21.72957922)
(198.32475308,19.26596641) ... (158.11078724,-49.91437661)
(219.79342843,-62.06756014) ( 69.92358315,-166.19385119)]
('rec_data ndim: ',1)
(' size: ',206705)
(' shape: ',(206705,))
(' dtype: ',dtype([('x','<f8'),('y','<f8')]))
然后使用函数将其更改为非结构化数组
arr_data = root_numpy.rec2array(rec_data)
现在看起来像这样
============ arr_data
<type 'numpy.ndarray'>
[[ 269.05515748 24.71801578]
[ 276.96505874 21.72957922]
[ 198.32475308 19.26596641]
...
[ 158.11078724 -49.91437661]
[ 219.79342843 -62.06756014]
[ 69.92358315 -166.19385119]]
('arr_data ndim: ',2)
(' size: ',413410)
(' shape: ',2))
(' dtype: ',dtype('float64'))
如何将“ new_data”转换回与rec_data格式完全相同的记录数组?
很抱歉,如果我的符号和/或术语在某些情况下不正确,因为我还是numpy数组的新手。
我尝试过
new_rec = np.array(new_data,dtype=rec_data.dtype)
和
new_rec = np.array(new_data,dtype=[('x',np.float64),np.float64)])
但是这些都不是我想要的。 什么是最优雅的解决方案,请您帮忙?