Package: array-to-latex
The modulearray_to_latexconverts a NumPy/SciPy array or Pandas Numerical DataFrame to a LaTeX
array or table usingPython 3.x styleformatting of the result or a format usable for plotting within LaTeX using pgfplots. Note that as of0.83itdoesadd
the column formatting arguments (for example,{ccc…}) when the user chooses to usearray. I’m happy
to have someone create a better solution but this at least makes a copied array immediately usable. I
preferbmatrixor similar. `Play with it onmybinder.org!A NumPy-focused re-envisioned converter based, in part, on this isnumpyarray_to_latex. Also, availablepip install. It incorporates more sophisticated “sub” markup capabilities. Check it out!Recent updates follow, with a more complete list towards the end of this document. If you don’t see the current version in this list it’s likely because I (again) forgot to update it when pushing out a new version. Please see thereadmeon GitHub.0.81: Bug fixes in requirements and to_clp0.82: Raise ImportError exception when incorrect datatype used.0.83: Now puts a default format in when returning as anarrayobject.0.90: Addcoordsformat for use in plotting within LaTeX using pgfplots.0.91: Improve the output for scientificenotation.Install usingpip install--userarray_to_latexfrom your command prompt,not the Python prompt.Please read the help. It explains all options. To try it, seethe online mybinder.org demo. It documents illustrates application to numerical Pandas DataFrames.importnumpyasnpimportarray_to_latexasa2lA=np.array([[1.23456,23.45678],[456.23,8.239521]])a2l.to_ltx(A,frmt='{:6.2f}',arraytype='array')will print the LaTeX code to your output.importnumpyasnpimportarray_to_latexasa2lA=np.array([[1.23456,23.45678],[456.23,8.239521]])latex_code=a2l.to_ltx(A,frmt='{:6.2f}',arraytype='bmatrix',print_out=False)will put the LaTeX code into variablelatex_code.importnumpyasnpimportarray_to_latexasa2lA=np.array([[1.23456,23.45678],[456.23,8.239521]])a2l.to_clp(A,frmt='{:6.2f}',arraytype='bmatrix')will put the array onto your clipboard.If you will be using the same conversion over and over, you can define your own by using alambdafunction:to_tex=lambdaA:a2l.to_ltx(A,frmt='{:6.2f}',arraytype='bmatrix',mathform=True)to_tex(A)so you can now use your functionto_texrepeatedly with your specified settings. More detailed information on usage is in the help.importarray_to_latexasa2lhelp(a2l.to_ltx)Interesting alternative approaches arenp_array_to_latexandtab2latex (convert numpy array to longtable file).Like this module,buy me a coffee!.New in0.37: Now handles complex arrays.New in0.38: Aligns columns neatly.0.40: Critical upgrade- 0.37-0.38 formatted incorrectly.0.41: Critical upgrade- 0.37-0.40 formatted incorrectly.New in0.43: Now handles 1-D Arrays. See new optionrowNew in0.50: Now works with Pandas DataFrames0.51: Bug fix- remove extra blank lines in DataFrame tabular output0.52: A few documentation typos fixed. No code changed.0.60: Now handles strings in Pandas Dataframes. Fixes bug in exponentials and handling of exponentials. Please report errors!0.61: Minor documentation improvements. No code changed.0.70: Addedmathform. When set toTrue(default), returns 10 to superscript form.0.71: Line breaks brokereadme.rstonpypi. No code change.0.72: Line breaks brokereadme.rstonpypi. No code change.0.73: pypi won’t handle mathjax. It makes me sad. No code change.0.74: Not released0.75: output improvements (short-lived release)0.76: Printing made better, allows outputs, addedprint_outboolean to turn off printing0.80: Return to previous interface while still enabling returnedLaTeX string.0.81: Bug fixes in requirements and to_clp0.82: Raise ImportError exception when incorrect datatype used.0.83: Add formatting defaults when using array versus bmatrix, etc.0.90: Addcoordsformat for use in plotting within LaTeX using pgfplots.0.91: Improve the output for scientificenotation.