I have a numpy float array and an int array of the same length. I would like to concatenate them such that the output has the composite dtype (float, int). column_stacking them together just yields a float64 array:
import numpy
a = numpy.random.rand(5)
b = numpy.random.randint(0, 100, 5)
ab = numpy.column_stack([a, b])
print(ab.dtype)
float64
Any hints?
np.zeros(...)from it, and assign the respective fields. Your link has more information on creating structured arrays. I don't think it mentionscolumn_stack.pd.DataFrame({'a':a, 'b':b})- should preserve dtypesnp.rec.fromarrays([a,b])if a recarray is ok