What is the correct format and syntax for reading data with subarrays into numpy structured array?

36 views Asked by At

I'm trying to use np.genfromtxt to read in a text file into a variety of data types, some of which are ideally sub arrays, however I can't seem to find the right code or input format for this, I've managed to get numpy to complain I both have too many and too few columns!

example data:

id;bar;foo;snakes
1;2.46;2.616;(1,1)

(or without brackets, e.g. 1;2.46;2.616;1,1 )

x = np.genfromtxt(file, delimiter=';', names=True, dtype='u4,f8,f8,(2,)u4')

Results in "ValueError: could not assign tuple of length 4 to structure with 5 fields."

id;bar;foo;snakes
1;2.46;2.616;1;1

Results in "ValueError: Some errors were detected ! Line #2 (got 5 columns instead of 4)"

Tried different delimiters. Is this not possible? The two different errors suggests it should be but I'm just not getting the correct syntax or data format

0

There are 0 answers