我有一些符號計算下面的代碼:如何在sympy中批量替換?
from sympy import *
import numpy
A = MatrixSymbol('A',2,2)
f = Matrix(A).det() # for example only, the actual function is of the same flavor
如何替代A
與相同尺寸的明確矩陣?我試着下面的代碼,但它不會產生期望的結果:
f.subs(A,Matrix(numpy.random.rand(2,2)))
返回:
Matrix([
[ 0.204259256795002, 0.198427966386296],
[0.0929675373783559, 0.516653291115676]])[0, 0]*Matrix([
[ 0.204259256795002, 0.198427966386296],
[0.0929675373783559, 0.516653291115676]])[1, 1] - Matrix([
[ 0.204259256795002, 0.198427966386296],
[0.0929675373783559, 0.516653291115676]])[0, 1]*Matrix([
[ 0.204259256795002, 0.198427966386296],
[0.0929675373783559, 0.516653291115676]])[1, 0]
這你可能感興趣的: [SymPy - 替代sybolic在矩陣中的條目(http://stackoverflow.com/questions/23208838/sympy-substitute-sybolic-entries -in-A-矩陣); [如何用symPy和numPy替換矩陣符號](http://stackoverflow.com/questions/16904924/how-to-substitute-symbol-for-matrix-using-sympy-and-numpy);和https://github.com/sympy/sympy/issues/2962 – agold