I am trying to create a recarray from a series of numpy arrays with column names and mixed variable types.
The following works but is slow:
import numpy as np
a = np.array([1,2,3,4], dtype=np.int)
b = np.array([6,6,6,6], dtype=np.int)
c = np.array([-1.,-2.-1.,-1.], dtype=np.float32)
d = np.array(list(zip(a,b,c,d)),dtype = [('a',np.int),('b',np.int),('c',np.float32)])
d = d.view(np.recarray())
I think there should be a way to do this with np.stack((a,b,c), axis=-1), which is faster than the list(zip()) method. However, there does not seem to be a trivial way to do the stacking an preserving column types. This link does seem to show how to do it, but its pretty clunky and I hope there is a better way.
Thanks for the help!
np.rec.fromarraysis probably what you want: