也许使用lambdify:
import sympy as syimport numpy as np from sympy.abc import x, yz = ((x+y)**2).expand()print(z)# x**2 + 2*x*y + y**2X = np.arange(6).reshape(2,3)Y = np.arange(1,7).reshape(2,3)f = sy.lambdify((x, y), z, 'numpy')print(f(X, Y))# [[ 1 9 25]# [ 49 81 121]]assert np.allclose(f(X, Y), (X**2 + 2*X*Y + Y**2))
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)