Let me say I created a file with this three lines
A\tB\tC
name1\t1\t2
name2\t1.1\t2.2
where \t corresponds to the delimiter. I read it using this numpy function
data = np.genfromtxt('test.txt', delimiter='\t', dtype=None, encoding='ascii')
Data is a numpy nd array with shape (3,3). I would like to rearrange it into different data structures such as
fileHeader = data[0, :]
names = data[1:, 0]
values = data[1:, 1:]
fileHeader and names should be list of strings or np.str_ without the character ' leading and trailing. values should be a nd array of float64 without the character ' leading and trailing.
How can I make this conversion? Thank you all in advance!
Your code, showing the results (which you should have done!):
So what's the problem?
'A'is the normal display of a string. TheFalse'is filler for the trailing empty field (after the last\t).We could stript off the
Falsewith:and convert the numbers to float with: