from sympy import *
def test_matrix():
A = Matrix([[x, x*y], [sin(z)+4, x**z]])
sol = Matrix([[1, 2], [sin(3)+4, 1]])
f = lambdify((x,y,z), A, modules="sympy")
assert f(1,2,3) == sol
f = lambdify((x,y,z), (A, [A]), modules="sympy")
assert f(1,2,3) == (sol,[sol])
https://www.kutu66.com/Python-Module-Examples/article_66605
实例 1
复制
def test_threaded(): @threaded def function(expr, *args): return 2*expr + sum(args) assert function(Matrix([[x, y], [1, x]]), 1, 2) == Matrix([[2*x + 3, 2*y + 3], [5, 2*x + 3]]) assert function(Eq(x, y), 1, 2) == Eq(2*x + 3, 2*y + 3) assert function([x, y], 1, 2) == [2