mirror of
https://github.com/rasbt/python_reference.git
synced 2025-01-18 15:27:09 +00:00
first commit
This commit is contained in:
parent
d294ad3078
commit
8c1e8d4efc
1255
benchmarks/.ipynb_checkpoints/cython_least_squares-checkpoint.ipynb
Normal file
1255
benchmarks/.ipynb_checkpoints/cython_least_squares-checkpoint.ipynb
Normal file
File diff suppressed because one or more lines are too long
2203
benchmarks/ccy_classic_lstsqr.c
Normal file
2203
benchmarks/ccy_classic_lstsqr.c
Normal file
File diff suppressed because it is too large
Load Diff
10
benchmarks/ccy_classic_lstsqr.pyx
Normal file
10
benchmarks/ccy_classic_lstsqr.pyx
Normal file
|
@ -0,0 +1,10 @@
|
|||
|
||||
def ccy_classic_lstsqr(x, y):
|
||||
""" Computes the least-squares solution to a linear matrix equation. """
|
||||
x_avg = sum(x)/len(x)
|
||||
y_avg = sum(y)/len(y)
|
||||
var_x = sum([(x_i - x_avg)**2 for x_i in x])
|
||||
cov_xy = sum([(x_i - x_avg)*(y_i - y_avg) for x_i,y_i in zip(x,y)])
|
||||
slope = cov_xy / var_x
|
||||
y_interc = y_avg - slope*x_avg
|
||||
return (slope, y_interc)
|
1255
benchmarks/cython_least_squares.ipynb
Normal file
1255
benchmarks/cython_least_squares.ipynb
Normal file
File diff suppressed because one or more lines are too long
9
benchmarks/setup.py
Normal file
9
benchmarks/setup.py
Normal file
|
@ -0,0 +1,9 @@
|
|||
|
||||
from distutils.core import setup
|
||||
from distutils.extension import Extension
|
||||
from Cython.Distutils import build_ext
|
||||
|
||||
setup(
|
||||
cmdclass = {'build_ext': build_ext},
|
||||
ext_modules = [Extension("ccy_classic_lstsqr", ["ccy_classic_lstsqr.pyx"])]
|
||||
)
|
Loading…
Reference in New Issue
Block a user