1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] What is the best way to convert a SymPy matrix to a NumPy array/matrix?

Discussão em 'Python' iniciado por Stack, Setembro 13, 2025.

  1. Stack

    Stack Membro Participativo

    I am not sure if the approach I've been using in SymPy to convert a MutableDenseMatrix to a numpy.array or numpy.matrix is a good current practice.

    I have a symbolic matrix like:

    g = sympy.Matrix( [[ x, 2*x, 3*x, 4*x, 5*x, 6*x, 7*x, 8*x, 9*x, 10*x],
    [x**2, x**3, x**4, x**5, x**6, x**7, x**8, x**9, x**10, x**11]] )


    And I am converting to a numpy.array doing:

    g_func = lambda val: numpy.array( g.subs( {x:val} ).tolist(), dtype=float )


    where I get an array for a given value of x.

    Is there a better built-in solution in SymPy to do that?

    Continue reading...

Compartilhe esta Página