简体   繁体   English

如何在给定点找到多个变量的梯度?

[英]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.

相关问题 对于给定的点,如何在点列表中找到最近的点? - For a given point, how to find closest point in a list of points? 给定点的非线性pyomo约束的梯度 - Gradient of a nonlinear pyomo constraint at a given point 在Python中的给定点查找未知函数的梯度 - Finding gradient of an unknown function at a given point in Python 如何找到一个点的坐标,使其与给定的线成 135 度角? - How to find the coordinates of a point such that it makes a 135 degree angle with a given line? Python - 我怎样才能找到一条线在给定点的角度? - Python - how can i find the angle of a line at a given point? 如何为keras中的给定数据点指定多个标签? - How to specify multiple labels for a given data point in keras? 如何在给定线的另一个点和垂直线上的2个点的线上找到点的X坐标? - How to find the X coordinate of a point on a line given another point of the line and the 2 points on a perpendicular line? 如何在任何给定时间点从给定字符串中找到前10个单词。 蟒蛇 - How to find the top 10 words from a given string at any given point of time. Python 如何查找导致 RuntimeError 的变量:梯度计算所需的变量之一已被原位操作修改 - How to find which variable is causing RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation 如何在 opencv 中应用三点三角形渐变? - how to apply a three point triangle gradient in opencv?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM