我有一个包含符号的矩阵:
import random
from random import sample
rows=20
a,b = 0.5,1
pop=list(zip(sample(range(1, 100000), rows),sample(range(1, 100000), rows)))
profit = sample(range(1, 100000), rows)
#print(pop,profit)
mycombined=list(zip(pop,profit))
combined_array = np.asarray(mycombined)
print(combined_array)
m = len (combined_array)
it = 1500
#alpha = 0.01
J=0
for i in range(1,m,1):
bpop=combined_array[i][0][0]
apop=combined_array[i][0][1]
aprofit=combined_array[i][1]
temp=(bpop+apop-aprofit)**2
J=J+temp
我想用数字替换所有符号“t”。
提前致谢。
答案 0 :(得分:1)
A = sympy.Matrix([[sympy.exp(t),1,-1], [0,t,0], [0,t+1,0]]) # fixing your expression
print(A.subs(t, 5))
哪个给了
Matrix([
[exp(5), 1, -1],
[ 0, 5, 0],
[ 0, 6, 0]])