How to transform sympy "vector" to numpy array?

Viewed 113

I want to do a function and calculate its Jacobian, it helped me with sympy to derive but now I cannot value with numpy, as I was doing previously. I don't know how to pass every entry from Jacobian to a ndarray. since the type of Jacobian [1] [1] is sympy.core.add.Add and that when value is numpy.ndarray. but I don't know how to value either.

import numpy as np
import sympy as sp
from string import ascii_lowercase as asi
vari=list(asi)[0:10]
var=sp.symbols(vari,real=True)
Funcion=[]
for i in np.arange(1, len(var)+1,1):
    if i==1:
        Funcion=Funcion+[(3-2*var[0])*var[0]-2*var[1]+1]
    elif i!=1 and i!=10:
        Funcion=Funcion+[(3-2*var[i-1])*var[i-1]-2*var[i-2]-2*var[i]+1]
    elif i==10:
        Funcion=Funcion+[(3-2*var[9])*var[9]-var[8]+1]

Jacobiano=[]
Gradiente=[]
for i in np.arange(0, len(var),1): #varia la funcion
    Gradiente=[]
    for j in np.arange(0, len(var),1): #varia la fila (lo mato a derivadas)
        Gradiente=Gradiente+[sp.diff(Funcion[i],var[j])]
    Jacobiano=Jacobiano+[Gradiente]
0 Answers
Related