#record 数组转 structured数组:
structured_arr = record_arr.view(record_arr.dtype.fields, np.ndarray)
#增加列:
import numpy.lib.recfunctions as rft
colarr1 = np.array([...])
colarr2 = np.array([...])
array2 = rft.append_fields(structured_array, names=['colname1', 'colname2'], data=[colarr1, colarr2])
1
ruoyu0088 2018-12-01 20:13:19 +08:00 1
文档里面有:
arr2 = recordarr.view(recordarr.dtype.fields or recordarr.dtype, np.ndarray) 但是添加列应该需要复制所有数据。 |
2
ghhardy OP @ruoyu0088 非常感谢!是的,numpy.lib.recfunctions 就是通过复制数组实现的 structrued 增加列
|