深度学习 / 默认 · February 19, 2022 0

Python中numpy求函数的导数实现方法

Table of Content

https://www.py.cn/jishu/jichu/20428.html

https://www.sympy.org/en/index.html

from sympy import *
import numpy as np
x = Symbol('x')
y = x**2 + 1
yprime = y.diff(x)
yprime

$\displaystyle 2 x$

f = lambdify(x, yprime, 'numpy')
f(np.ones(5))
array([2., 2., 2., 2., 2.])
from sympy import *
init_printing(use_unicode=True)
x = symbols("x")
f = log(x)
f

$\displaystyle \log{\left(x \right)}$

diff(f, x)

$\displaystyle \frac{1}{x}$

diff(f, x, 2)

$\displaystyle – \frac{1}{x^{2}}$

%d bloggers like this: