Return Numpy and Pandas arrays as formatted LaTeX arrays.
Project description
The module array_to_latex converts a NumPy/SciPy array or Pandas Numerical DataFrame to a LaTeX array or table using Python 3.x style formatting of the result or a format usable for plotting within LaTeX using pgfplots. Note that as of 0.83 it does add the column formatting arguments (for example, {ccc…}) when the user chooses to use array. I’m happy to have someone create a better solution but this at least makes a copied array immediately usable. I prefer bmatrix or similar. `
Play with it on mybinder.org!
A NumPy-focused re-envisioned converter based, in part, on this is numpyarray_to_latex. Also, available pip 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 the readme on GitHub.
Install using pip install --user array_to_latex from your command prompt, not the Python prompt.
Please read the help. It explains all options. To try it, see the online mybinder.org demo. It documents illustrates application to numerical Pandas DataFrames.
import numpy as np
import array_to_latex as a2l
A = 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.
import numpy as np
import array_to_latex as a2l
A = 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 variable latex_code.
import numpy as np
import array_to_latex as a2l
A = 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 a lambda function:
to_tex = lambda A : a2l.to_ltx(A, frmt = '{:6.2f}', arraytype = 'bmatrix', mathform=True)
to_tex(A)
so you can now use your function to_tex repeatedly with your specified settings. More detailed information on usage is in the help.
import array_to_latex as a2l
help(a2l.to_ltx)
Interesting alternative approaches are np_array_to_latex and tab2latex (convert numpy array to longtable file).
Like this module, buy me a coffee!.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
File details
Details for the file array_to_latex-0.92-py3-none-any.whl
.
File metadata
- Download URL: array_to_latex-0.92-py3-none-any.whl
- Upload date:
- Size: 6.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1a476781d4149161421472a9078095bf9ed26ba08a810ab4ffe4a937e8318de7 |
|
MD5 | 3b18b9f88aed6cdb4456369bad30eb48 |
|
BLAKE2b-256 | 46fc36f04896f937329af390a66067070bae2ec7c2511286359a00ff16bca924 |