Lets say I have three vectors a, b, and c:
a = np.array([1,2,3])
b = np.array([1.2, 3.2, 4.5])
c = np.array([True, True, False])
What is the simplest way to turn this into a matrix d of differing data types and column labels, as such:
d = ([[1, 1.2, True],
[2, 3.2, True],
[3, 4.5, False]],
dtype=[('aVals','i8'), ('bVals','f4'), ('cVals','bool')])
So that I can then save this matrix to a .npy file and access the data as such after opening it;
>>> d = np.load('dFile')
>>> d['aVals']
np.array([1,2,3], dtype = [('aVals', '<i8)])
I have used a cimple column_stack to create the matrix, but I am getting a headache trying to figure out how to include the datatypes and column names, since column_stack does not accept a dtype argument, and I can't see a way to add field names and data types after the column_stack is preformed. It is worth mentioning that the vectors a, b, and c have no explicit datatypes declared upon their creation, they are as shown above.
np.savez(outfile, aVals=a, bVals=b, cVals=c)to save all three arrays to a compressed npz file.