【发布时间】:2020-12-16 20:07:10
【问题描述】:
我正在尝试使用写在帖子How to find the approximate basic period or GCD of a list of numbers 中的 SageMath 代码。这段代码在 CoCalc 中工作,但我无法让它在我的 IDE 中的 Python 中运行。我已经导入了 numpy 和 sagemath,并根据需要引用了每一个来定义数学函数,但我无法让 find_local_maximum 函数工作。见下文。
代码:
import numpy as np
import sagemath as sm
def mean_x(factor, values):
return sum([np.cos(2*np.pi*v/factor) for v in values])/len(values)
def mean_y(factor, values):
return sum([np.sin(2*np.pi*v/factor) for v in values])/len(values)
def calculatePeriodAppeal(factor, values):
mx = mean_x(factor, values)
my = mean_y(factor, values)
appeal = np.sqrt(mx**2+my**2)
return appeal
def calculateBestLinear(factor, values):
mx = mean_x(factor, values).n()
my = mean_y(factor, values).n()
y0 = factor*np.atan2(my,mx)/(2*np.pi).n()
err = 1-np.sqrt(mx**2+my**2).n()
return [factor*x + y0, err]
def calculateGCDAppeal(factor, values):
mx = mean_x(factor, values)
my = mean_y(factor, values)
appeal = 1 - np.sqrt((mx-1)**2+my**2)/2
return appeal
testSeq = [552,827,275,809,534]
gcd = calculateGCDAppeal(x, testSeq)
agcd = sm.find_local_maximum(gcd,20,30)
print(agcd)
np.plot(gcd,(x, 20,30))
错误:
Traceback (most recent call last):
File "<ipython-input-163-fecb5397afab>", line 31, in <module>
agcd = sm.find_local_maximum(gcd,20,30)
AttributeError: module 'sagemath' has no attribute 'find_local_maximum'
【问题讨论】:
标签: python jupyter-notebook spyder nameerror sage