57 lines
980 B
Python
57 lines
980 B
Python
import numpy as np
|
|
|
|
def linfit(x, y):
|
|
"""
|
|
Return linear fit
|
|
"""
|
|
p = np.polyfit(x, y, 1)
|
|
f = np.poly1d(p)
|
|
x_fit = np.linspace(min(x), max(x), 100)
|
|
y_fit = f(x_fit)
|
|
yhat = f(x)
|
|
ybar = np.sum(y)/len(y)
|
|
ssreg = np.sum((yhat - ybar)**2)
|
|
sstot = np.sum((y - ybar)**2)
|
|
R2 = ssreg / sstot
|
|
return (p, x_fit, y_fit, R2)
|
|
|
|
def test():
|
|
return np.ones(5)
|
|
|
|
|
|
def test2(name, x=None, y=None, **kwargs):
|
|
print (name,x,y)
|
|
ret = y*x
|
|
print (ret)
|
|
print(kwargs.get("z", 0.0))
|
|
return ret
|
|
|
|
def add(x,y,z):
|
|
return x+y+z
|
|
|
|
def read_dev(dev):
|
|
return dev.read()
|
|
|
|
|
|
|
|
def print_dict(d):
|
|
for k in d.keys():
|
|
print (k, d[k])
|
|
ret = {}
|
|
ret.update(d)
|
|
return ret
|
|
|
|
def get_tuple():
|
|
return (1,2,3)
|
|
|
|
#x=np.array([0,1,2,3,4,5,6,7,8,9])
|
|
#y=np.array([1,2,3,6,9,6,3,2,1,0])
|
|
#print( linfit(x,y) )
|
|
|
|
|
|
#x=(0,1,2,3,4,5,6,7,8,9)
|
|
#y=(1,2,3,6,9,6,3,2,1,0)
|
|
#print( linfit(x,y) )
|
|
|
|
|
|
#print_dict({"a":1, "b":2}) |