偏导数

2024-09-25 08:37:38 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个接受多元变量x的函数,这里x=[x1,x2,x3]。假设我的函数看起来像: f(x,T)=美国运输部(x,T)+np.exp.公司(美国运输部(x,T)其中T是常数。在

我对查找df/dx1、df/dx2和df/dx3函数很感兴趣。在

我使用scipydiff取得了一些成功,但是我有点怀疑,因为它使用的是数值差异。昨天,我的同事指给我签名。因为它似乎是一个流行的包,我希望这里的人知道如何使用这个包获得部分差异化。我对这个库的初始测试表明grad函数只对第一个参数进行微分。我不知道如何把它扩展到其他论点。任何帮助都将不胜感激。在

谢谢。在


Tags: 函数dfnp常数公司差异数值x1
1条回答
网友
1楼 · 发布于 2024-09-25 08:37:38

我在autograd源代码中找到了grad函数的以下描述:

def grad(fun, x)
"Returns a function which computes the gradient of `fun` with
respect to positional argument number `argnum`. The returned
function takes the same arguments as `fun`, but returns the
gradient instead. The function `fun`should be scalar-valued. The
gradient has the same type as the argument."

所以

^{pr2}$

另外,一定要使用numpy libaray,它带有autograd

import autograd.numpy as np

而不是

import numpy as np

为了利用所有numpy函数。在

相关问题 更多 >