本文整理匯總了Python中db.DB.load_roots方法的典型用法代碼示例。如果您正苦於以下問題:Python DB.load_roots方法的具體用法?Python DB.load_roots怎麽用?Python DB.load_roots使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類db.DB
的用法示例。
在下文中一共展示了DB.load_roots方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: animate_flat_plot
# 需要導入模塊: from db import DB [as 別名]
# 或者: from db.DB import load_roots [as 別名]
def animate_flat_plot(f, step=10, limit=None, figsize=None):
db = DB()
if type(f) != list:
f = [f, ]
# Figure out how many frames we will have
# ...not very efficient
max = 1
for i in range(len(f)):
n = len(db.load_roots(f[i], raw=False))
if max < n:
max = n
if (limit and max < limit) or not limit:
limit = max
frames = ceil(limit / step)
plots = list()
for i in range(frames):
j = (i + 1) * step
plots.append(flat_plot(f, j, False))
figsize = (15, len(f))
return animate(plots, figsize=figsize)
示例2: weyl_sum
# 需要導入模塊: from db import DB [as 別名]
# 或者: from db.DB import load_roots [as 別名]
def weyl_sum(f,l,stop=None):
db = DB()
roots = db.load_roots(f)[:stop]
sum = 0
for n in range(len(roots)):
print sum
print roots[n]
sum += 1 / (n + 1) * exp(2*pi.n()*l*roots[n].n()).n()
return sum
示例3: distance_prime
# 需要導入模塊: from db import DB [as 別名]
# 或者: from db.DB import load_roots [as 別名]
def distance_prime(f):
db = DB()
roots = db.load_roots(f, raw=True)
p = int(roots[0][1])
lst = list()
for r in roots:
p1 = int(r[1])
if p != p1:
lst.append((p, p1 - p))
p = p1
return lst
示例4: density_interval
# 需要導入模塊: from db import DB [as 別名]
# 或者: from db.DB import load_roots [as 別名]
def density_interval(f, low, high, limit=None, convergence=False):
"""Return the density for the interval [low, high]."""
db = DB()
roots = db.load_roots(f, raw=False)[:limit]
total = len(roots)
count = 0
if convergence:
lst = list()
for i in range(len(roots)):
if low <= roots[i] <= high:
count += 1
if convergence:
lst.append((i + 1, count / (i + 1)))
if convergence:
return lst
else:
return count / total
示例5: flat_plot
# 需要導入模塊: from db import DB [as 別名]
# 或者: from db.DB import load_roots [as 別名]
def flat_plot(f, limit=None, legend=False, save=False):
"""
Produces a plot of normalized roots for given irreducible f
INPUT:
`f` -- Either a polynomial or a list of polynomials
`limit` -- Limit the number of roots used in the plot
`legend` -- Show lables for polynomials
OUTPUT:
Sage graphics object
"""
db = DB()
if type(f) != list:
f = [f, ]
plot = scatter_plot([])
classes = list() # For color coordination
for i in range(len(f)):
# Identify a class of f by (degree, group id) tuple.
degree = f[i].degree()
gid = f[i].galois_group()._n
cid = (degree, gid)
if classes.count(cid) == 0:
classes.append(cid)
color = classes.index(cid)
# Add plots
roots = db.load_roots(f[i], raw=False)[:limit]
points = [(j,i + 1) for j in roots]
plot_opts = {'edgecolor': colors[0],
'facecolor': colors[color],
'markersize': 10}
plot += scatter_plot(points, **plot_opts)
# Add labels
count = len(roots)
label = str(i + 1) + ": " + "D" + str(degree) + "G" + str(gid)
# If the database contains more roots than given limit, do not add count
# on the label, otherwise add count
if not limit or count != limit:
label += "(" + str(count) + ")"
label_opts = {'fontsize': 8,
'rgbcolor': (20, 20, 20),
'horizontal_alignment': 'left'}
plot += text(label, (1.02, i + 1), **label_opts)
if legend:
legend_opts ={'fontsize': 8,
'rgbcolor': (20, 20, 20),
'horizontal_alignment': 'left'}
legend_text = "(" + str(i + 1) + ") " + str(f[i])
plot += text(legend_text, (0.01, -i-1), **legend_opts)
if not limit:
limit = ""
plot += text(limit, (1,len(f)-0.2), horizontal_alignment='right')
for i in range(11):
plot += line([(i * 0.1, -100), (i * 0.1, 100)], alpha = 0.2, rgbcolor = (0, 0, 0))
plot.axes(False)
plot.axes_color((0.2, 0.2, 0.2))
if not legend:
axes_range = {'xmin': 0, 'xmax': 1.3, 'ymin': 0.5, 'ymax': len(f) + 0.5}
else:
axes_range = {'xmin': 0, 'xmax': 1.3, 'ymin': -len(f), 'ymax': len(f)}
plot.set_axes_range(**axes_range)
return plot