[英]Derivatives of a matrix using Sympy
I am learning Sympy to know the Symbolic operations in Python.我正在学习 Sympy 以了解 Python 中的符号操作。 I want to find out the derivative of a matrix.我想找出矩阵的导数。
How could I derivate the matrix in respect to b.我如何推导关于 b 的矩阵。
import sympy as sp
B = sp.Matrix([[(a*c),(b**2)],[(b*d),(d*a)]])
B
Assuming you want the usual matrix-by-scalar derivative and that you're using sympy 1.7, then the following should work:假设您想要通常的 矩阵标量导数并且您使用的是 sympy 1.7,那么以下应该可以工作:
import sympy as sp
a, b, c, d = sp.symbols("a b c d")
B = sp.Matrix([[(a*c),(b**2)],[(b*d),(d*a)]])
B.diff(b)
Returns:回报:
Matrix([
[0, 2*b],
[d, 0]])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.