【发布时间】:2010-11-13 08:18:34
【问题描述】:
我正在使用here 描述的算法将高斯钟形曲线拟合到我的数据中。
如果我生成我的数据数组:
x=linspace(1.,100.,100)
data= 17*exp(-((x-10)/3)**2)
一切正常。
但如果我使用
从文本文件中读取数据file = open("d:\\test7.txt")
arr=[]
data=[]
def column(matrix,i):
return [row[i] for row in matrix]
for line in file.readlines():
numbers=map(float, line.split())
arr.append(numbers)
data = column(arr,300)
x=linspace(1.,115.,115)
我收到错误消息:
Traceback (most recent call last):
File "readmatrix.py", line 60, in <module> fit(f, [mu, sigma, height], data)
File "readmatrix.py", line 42, in fit if x is None: x = arange(y.shape[0])
AttributeError: 'list' object has no attribute 'shape'
据我所知,数据中包含的值是正确的,它看起来像:
[0.108032, 0.86181600000000003, 1.386169, 3.2790530000000002, ... ]
有人知道我做错了什么吗?
谢谢!
【问题讨论】:
-
@Dzz:您甚至没有包括源代码的相关部分。第 42 行是您发生错误的地方,因为您使用的是“y.shape[0]”,而 y 是一个没有 shape 属性的列表类型。您需要提供更多来源,以便我们正确找到错误。
-
对不起,我希望通过链接到代码来减少帖子中的文字数量。