I have this Mathematica (output) vector that I'd like to convert to Python:

{{k[0],-o[3] k[10]-o[2] k[13]-k[19]+k[13] x[4]+k[13] x[5]+k[10] x[6]+k[10] x[7]+k[10] x[8]+k[13] x[9]+k[13] x[10]+k[10] x[11],0,0,k[13] x[1],k[13] x[1],k[10] x[1],k[10] x[1],k[24]+k[10] x[1],k[13] x[1],k[26]+k[13] x[1],k[10] x[1]},{-k[0]-k[17],0,0,0,k[3],k[5],0,0,0,0,0,0}}

I want the variables to stay the same, unlike InputForm, that converts e.g. k[1] to StringForm["k[``]", 1]; plus, I want the implicit multiplications (e.g. k[13] x[5]) to appear with an asterisk.

I don't mind the brackets, I've found a function that solves this last problem.

Thanks in advance! :)

  • 1
    $\begingroup$ I would look at some of the "Form" commands: ?*Form For example, CForm and FortranForm are pretty close to the python code you are looking for, $\endgroup$
    – bill s
    Oct 28, 2019 at 0:49
  • $\begingroup$ Related: Prepare mathematica output to be parsed in Python $\endgroup$
    – C. E.
    Oct 28, 2019 at 20:39


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.