python - numpy.genfromtxt seems to ignore dtype -


i trying load csv file consisting float types.

data = np.genfromtxt(self.file,dtype=float,delimiter=self.delimiter,names = true) 

but returns array of tuples. based on search should return tuples non-homogenous arrays. numpy.genfromtxt produces array of looks tuples, not 2d array—why?. when remove names=true, return 2d array. possible return array names in link?

lines csv:

0 _id|1 age|2 unkown|3 male|4 female|5 match-start|6 score 8645632250|7744|0|1|0|1|10 

(there more columns, wrote first 6 of them.)

i used code better names of columns:

def obtain_data(self): open(self.file, 'r') infile:   first_line = infile.readline()   labels = first_line.split('|')   labels = list(map(trunc_before,labels))   data = np.genfromtxt(self.file,dtype=float,delimiter=self.delimiter,names = labels,skip_header=1)   return data,  np.asarray(labels) 

it sounds you're asking whether it's possible have standard 2d array while having named columns. isn't. (at least not in sense seem asking.)

an "array names" is structured array -- it's array of records (not tuples), each of has named fields. think of way: names aren't attached array, they're attached "tuples" -- records. fact data of homogenous type doesn't matter.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -