Add files via upload
This commit is contained in:
parent
64b80ad64e
commit
1675deb3d2
1 changed files with 9 additions and 2 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
# The following are snap functions for finding a best approximated integer or rational number for a real number:
|
# The following are snap functions for finding a best approximated integer or rational number for a real number:
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
from sympy import Rational
|
||||||
|
|
||||||
def bestApproximation(x,imax):
|
def bestApproximation(x,imax):
|
||||||
# The input is a numpy parameter vector p.
|
# The input is a numpy parameter vector p.
|
||||||
|
|
@ -75,4 +76,10 @@ def rationalSnap(p, top=1):
|
||||||
p = np.array(p)
|
p = np.array(p)
|
||||||
snaps = np.array(list(bestApproximation(x,100) for x in p))
|
snaps = np.array(list(bestApproximation(x,100) for x in p))
|
||||||
chosen = np.argsort(snaps[:, 3])[:top]
|
chosen = np.argsort(snaps[:, 3])[:top]
|
||||||
return dict(list(zip(chosen, snaps[chosen, 0:3])))
|
d = dict(list(zip(chosen, snaps[chosen, 1:3])))
|
||||||
|
d = {k: f"{val[0]}/{val[1]}" for k,val in d.items()}
|
||||||
|
|
||||||
|
return d
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue