#Save this to "Test array.txt", without # #1 1 #2 4 #3 9 #4 16 #5 25 #6 36 #7 49 #8 64 #9 81 #10 100 infile = open('Test array.txt', 'r') xarray = [] yarray = [] xyarray = [] for line in infile: x, y = line.split() xarray.append(float(x)) yarray.append(float(y)) print xarray print yarray # To get a single 2D array, need to know length of file to pre-define arrays import numpy infile = open('Test array.txt','r') nlines = len(infile.readlines()) infile.seek(0) print nlines # Create array of zeros of the correct shape xyarray = numpy.zeros(( 2,nlines) ) i = 0 for line in infile: x, y = line.split() xyarray[0,i] = float(x) xyarray[1,i] = float(y) i = i + 1 print xyarray print xyarray print xyarray[1,5]