csv - Python Index error (out of bounds) accessing element in 2D array -


i'm trying access element of 2d array created data in csv file. can print array fine.

when try access array find element (i.e. number 'row' 1 'column' 5) throws error:

c:\users\aclayton\current\python begin\code_tester.py in create_alldata(whichfile) 37     array_data=np.array(all_data) ---> 38     nb=array_data[1][5] indexerror: index 1 out of bounds axis 0 size 1 

if great

def create_alldata(whichfile):     open_file = open(infile, 'rb')                            csv_current=csv.reader(open_file)                          all_data=[]                                   np.array(all_data)     row in open_file:                  all_data.append(row)                                 open_file.close()     array_data=np.array(all_data)     nb=array_data[1][5]     return array_data,       path=raw_input('what directory?') infile in glob.glob(os.path.join(path, '*.csv')):      create_alldata(infile) 

if want read multidimensional data csv, use numpy.genfromtxt() or numpy.loadtxt() functions, depending on how complete csv file (use former if row length varies, latter if constant , uniform).

you instead trying build multidimensional numpy array manually, discovered doesn't quite work that.

import numpy  def create_alldata(whichfile):     return numpy.genfromtxt(whichfile)                      

Comments

Popular posts from this blog

assembly - 8086 TASM: Illegal Indexing Mode -

Java, LWJGL, OpenGL 1.1, decoding BufferedImage to Bytebuffer and binding to OpenGL across classes -

javascript - addthis share facebook and google+ url -