数据转换错误与numpy

时间:2012-06-28 15:26:03

标签: python arrays numpy

我正在使mu代码更好,我看到numpy已经内置了一些非常漂亮的功能。但是,以下代码抛出了一个我无法解决的错误 解释:

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")

抛出错误

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

当我尝试阅读以下文件时:

  '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  

我做错了什么?我的代码应该很简单吗?

1 个答案:

答案 0 :(得分:1)

您要么重复标题行,要么将names指定为列表。

这导致每列被读取为以列标题开头的字符串类型。