I'm working on a linear regression program and when I try to convert the input file data to a float (it reads in as a string), I get this error. Perhaps someone can help me? I'm using Windows XP, and IDLE. (also the console screen).
Input file looks like this:
1.0 2.0
2.0 3.5
2.5 5.0
3.5 6.5
which are data points, x and y respectively.
Thanks!
TMS
Code:
#! /usr/bin/env python
import sys
import os
from numpy import *
numLst = [] #an empty list
if len(sys.argv) == 2:
infile = open(sys.argv[1], 'r')
elif len(sys.argv) <2:
infile = raw_input("Name of file: ")
elif len(sys.argv) > 2:
raise SyntaxError, "Too many arguments"
data = open(infile, 'r')
for x in data:
x = float(x) # HERE IS THE PROBLEM
numLst.append(x.strip('\n').split(" "))
a = array(numLst)
print a
1.0 2.0
2.0 3.5
2.5 5.0
3.5 6.5
which are data points, x and y respectively.
Thanks!
TMS
Comment