0

i am in the process of making mu code nicer and i saw that numpy has some very nifty functions already built-in. However the following code throws an error that i cannot explain:

data = numpy.genfromtxt('table.oout',unpack=True,names=True,dtype=None)

real_ov_data=np.float32(data['real_overlap'])
ana_ov_data= np.float32(data['Analyt_overlap'])
length_data =np.float32(data['Residues'])

plot(length_data,real_ov_data,label="overlapped Peaks, exponential function",marker="x", markeredgecolor="blue", markersize=3.0, linestyle=" ",color="blue")
plot(length_data,ana_ov_data,label="expected overlapped Peaks",marker="o", markeredgecolor="green", markersize=3.0, linestyle=" ",color="green")

throws the error

Traceback (most recent call last):
  File "length_vs_overlap.py", line 52, in <module>
    real_ov_data=np.float32(data['real_overlap'])
ValueError: invalid literal for float(): real_overlap
>Exit code: 1

when i am trying to read the following file:

  'Residues'  'Analyt_overlap'  'anz_analyt_overlap'  'real_overlap' 
  21          1.2502        29            0.0000  
  13          1.0306        25            0.0000  
  56          5.8513        84            2.8741  
  190         68.0940       329           28.4706 
  54          5.4271        83            2.4999  

What am i doing wrong? My piece of code should be simple enough?

6
  • 1
    It might help to see what gets printed out when you iterate through data, perhaps this numpy.genfromtxt('table.oout',unpack=True,names=True,dtype=None) isn't doing exactly what you think. Commented Jun 28, 2012 at 15:30
  • 1
    This works for me, the data loads just fine. An aside, you shouldn't have two namespaces for numpy. You have both numpy. and np.. I'd remove one of those import statements and unify it. Commented Jun 28, 2012 at 15:33
  • 1
    The fact that the data loads on the minimal example posted suggests that you are doing something fishy in the 50 lines of code before the error. Can you post a complete example where this fails, including all needed import statements? Commented Jun 28, 2012 at 15:35
  • ok, but the code is too long to be pasted here. i will just upload both code and data to pastebin. Commented Jun 28, 2012 at 16:11
  • code: pastebin.com/d3AsrSuc, table: pastebin.com/iP21ZYJS Commented Jun 28, 2012 at 16:15

1 Answer 1

1

You've either repeated the header line, or you're specifying the names as a list.

That's causing each column to be read as a string type starting with the column title.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.