我正在尝试使用postHow to find the approximate basic period or GCD of a list of numbers中编写的SageMath代码。这段代码在CoCalc中工作,但我无法在IDE中的Python中运行它。我已经导入了numpy和sagemath,并根据需要引用它们来定义数学函数,但是我无法让find_local_max函数工作。见下文
代码:
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'
看起来您运行了
pip install sagemath
安装了 PyPI的“sagemath”包:这是一个虚拟包,这样做并没有安装SageMath
使Sage库pip可安装的工作正在进行中,跟踪时间为
目前,访问SageMath功能实际上需要 安装SageMath,而不是PyPI中的虚拟“SageMath”包
如果目标是与Spyder一起使用,请参见
建议遵循最简单的路线,并 通过Conda安装Sage和Spyder
相关问题 更多 >
编程相关推荐