首页 > 解决方案 > sympy 提高矩阵元素的权力?

问题描述

我有一个sympy.Matrix带有象征性的元素。我想将每个元素提升到k一些k符号或数字的幂。有没有一种操作可以做到这一点?

标签: sympy

解决方案


您可以applyfunc为此使用:

In [2]: M = Matrix([[1, 2], [3, 4]])

In [3]: M.applyfunc(lambda e: e**2)
Out[3]: 
⎡1  4 ⎤
⎢     ⎥
⎣9  16⎦

https://docs.sympy.org/latest/modules/matrices/matrices.html#operations-on-entries


推荐阅读