It seems that the subs method is useless, and it seems that you need to use a function called sympy.lambdify.
subs_vs_lambdify.py
# coding:utf-8
import numpy as np
import sympy as sp
#Create a sympy variable
x = sp.Symbol('x')
y = sp.Symbol('y')
#Make an array of numpy
arrX = np.arange(12, dtype='float64').reshape((3, 4))
arrY = np.ones((3, 4))
#Create a sympy function
symbolFunc = 2*x + y
#Assign an array with the subs method
resSubs = symbolFunc.subs([(x, arrX), (y, arrY)])
print(resSubs)
# ==> 2*x + y
#It seems that the array cannot be calculated
#Try to calculate using lambdify
#First, create a function
lambdifyFunc = sp.lambdify([x, y], symbolFunc)
#Pass an array as an argument of the created function
resLambdify = lambdifyFunc(arrX, arrY)
print(resLambdify)
# ==> [[ 1. 3. 5. 7.]
# [ 9. 11. 13. 15.]
# [17. 19. 21. 23.]]
#This one calculated
Recommended Posts