我想转换记录阵列的列表 - D型是(UINT32,FLOAT32) - 进入D型细胞np.object
的numpy的数组:存储记录阵列
X = np.array(instances, dtype = np.object)
其中instances
是数据类型为np.dtype([('f0', '<u4'), ('f1', '<f4')])
的阵列列表。 然而,上面的语句会导致数组,其元素也np.object
类型:
X[0]
array([(67111L, 1.0), (104242L, 1.0)], dtype=object)
有谁知道为什么吗?
下面的语句应该是相当于上面却给人希望的结果:
X = np.empty((len(instances),), dtype = np.object)
X[:] = instances
X[0]
array([(67111L, 1.0), (104242L, 1.0), dtype=[('f0', '<u4'), ('f1', '<f4')])
感谢&问候, 彼得