I'd like to convert a list of record arrays -- dtype is (uint32, float32) -- into a numpy array of dtype np.object
:
X = np.array(instances, dtype = np.object)
where instances
is a list of arrays with data type np.dtype([('f0', '<u4'), ('f1', '<f4')])
.
However, the above statement results in an array whose elements are also of type np.object
:
X[0]
array([(67111L, 1.0), (104242L, 1.0)], dtype=object)
Does anybody know why?
The following statement should be equivalent to the above but gives the desired result:
X = np.empty((len(instances),), dtype = np.object)
X[:] = instances
X[0]
array([(67111L, 1.0), (104242L, 1.0), dtype=[('f0', '<u4'), ('f1', '<f4')])
thanks & best regards, peter