back to iatexture

Function readata

Read a dataset. The first collumn represents the class label and the others the descriptors

Function code

01. from numpy import *
02. 
03. def readata(f):
04.     conteudo = f.readlines()
05.     size_base = len(conteudo)
06.     feats = [0]*size_base
07.     labels = [0]*size_base
08. 
09.     for i in range(size_base):
10.         feats[i] = conteudo[i].split(',')
11.         labels[i] = feats[i][0]
12.         feats[i] = feats[i][1:-1]
13. 
14.     labels = array(labels).astype(int)
15.     feats = array(feats).astype(float)
16.     f.close()
17.     return labels,feats
1. from iatexture.readata import readata
2. fnwm = open(find_attachment_file("homemariana/text2Dsymnormal/nwmsym2d.txt"))
3. labels0,feats0 = readata(fnwm)
4. fnwm.close()
5. print feats0
[[  1.86076923e+02   1.97453254e+03  -2.07699240e+00 ...,   1.75286813e+00
    2.57496395e+00   1.00000000e+00]
 [  1.16076923e+02   1.04690966e+04   2.04711037e-01 ...,  -4.42848627e-01
   -1.65343595e+00   1.00000000e+00]
 [  7.91500000e+01   6.39452750e+03   1.17576557e+00 ...,   1.99777715e-01
   -1.60955787e+00   1.00000000e+00]
 ..., 
 [  1.30263158e+02   1.44760886e+04  -1.00964870e-01 ...,   2.08814588e-01
   -1.72004673e+00   1.00000000e+00]
 [  2.39923077e+02   3.31479290e+01  -9.03484145e-01 ...,  -4.19166021e-02
   -1.32623148e+00   1.00000000e+00]
 [  2.19666667e+02   2.88888889e+01   9.95617273e-01 ...,   3.88377693e-01
   -1.68644195e+00   1.00000000e+00]]