[英]How to find gradient of multiple variables at a given point?
I need to find gradient of function (x**2+y) at point [2, 4].我需要在点 [2, 4] 处找到 function (x**2+y) 的梯度。
import numdifftools as nd
import sympy as sym
from sympy import *
x, y = sym.symbols('x y')
def rosen(x, y):
return (x**2 + y)
grad = nd.Gradient(rosen)([2, 4])
print("Gradient of is ", grad)
TypeError: rosen() missing 1 required positional argument: 'y'
Argument to function passed to nd.Gradient
must be an array.传递给
nd.Gradient
的 function 的参数必须是一个数组。
import numdifftools as nd
def rosen(xy):
return (xy[0]**2 + xy[1])
grad = nd.Gradient(rosen)([2, 4])
print("Gradient of is ", grad)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.