- 论坛徽章:
- 1
|
大家好,我最近写了个脚本求二次项曲线拟合的斜率,但是13行一直报一个好像是数据格式的错误“TypeError: ufunc 'add' did not contain a loop with signature matching types dtype('<U191') dtype('<U191') dtype('<U191')” 请问大家知道怎么debug吗?多谢了!
- import numpy as np
- import os
- dir="new"
- out=open("curve_result.txt",'w+')
- files=os.listdir(dir)
- for file in files:
- if not os.path.isdir(file):
- f=open(dir+"/"+file);
- tmp=f.read().splitlines()
- y=str(tmp).replace("'","")
- print (y)
- x=[1,2,3,4,5,6,7,8,9,10]
- (k,b)=np.polyfit(x,y,1)
- print(file," %.3f" % (k),file=out)
复制代码
|
|