Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/324.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 为什么mpmath会起作用;“差别”;生成错误属性错误:';MPContext';对象没有属性';差异';?_Python_Differentiation_Mpmath - Fatal编程技术网

Python 为什么mpmath会起作用;“差别”;生成错误属性错误:';MPContext';对象没有属性';差异';?

Python 为什么mpmath会起作用;“差别”;生成错误属性错误:';MPContext';对象没有属性';差异';?,python,differentiation,mpmath,Python,Differentiation,Mpmath,我想用MPMath function diff来区分一个函数。为了尝试在一个简单的例子中是否一切正常,我使用了纪录片中描述的一个例子。但它抛出了错误“AttributeError:'MPContext'对象没有属性'difference'”。我使用的例子是: from mpmath import * dps=15 pretty = True diff(lambda x: x**2 + x, 1.0) 在这里,我也不明白,在纪录片中,他们显然使用了diff,只引入了两个参数(diff(f,x)

我想用MPMath function diff来区分一个函数。为了尝试在一个简单的例子中是否一切正常,我使用了纪录片中描述的一个例子。但它抛出了错误“AttributeError:'MPContext'对象没有属性'difference'”。我使用的例子是:

from mpmath import *

dps=15
pretty = True
diff(lambda x: x**2 + x, 1.0)
在这里,我也不明白,在纪录片中,他们显然使用了diff,只引入了两个参数(diff(f,x)),而文档中的函数示意图如下所示:

mpmath.diff(ctx, f, x, n=1, **options)
那么,为什么他们可以忽略“ctx”(不管这个变量应该是什么),这在语法上不应该是错误的,因为你必须将所有未预设的强制参数传递给函数(就像ctx=“something”)一样

提前多谢了,这对我真的很有帮助

亲切问候,, 乔纳森