BigThonkers / ThonkTools

Revolutionary wrappers for stupid lab stuff.
1 stars 3 forks source link

arrtex - Convert arrays to LaTeX tables #5

Open munnich opened 5 years ago

munnich commented 5 years ago

Basically, the goal is to be able to take both arrays and uarrays and output a LaTeX table, just like how csvtex takes a csv file and outputs it. Most of the code from csvtex can be reused (or turned to a conversion function and then used) for this. Ideal usage example: Input:

import numpy as np
import ThonkTools as TT

arr = np.array(0, 1, 2, 3)
out = TT.arrtex(arr, break=1)
print(out)

Output:

0 & 1 \\
2 & 3

Input with uncertainties:

from uncertainties import unumpy as unp
import ThonkTools as TT

arr = unp.uarray([0, 1, 2, 3], [0.0, 0.1, 0.2, 0.3])
out = TT.arrtex(arr, break=1)
print(out)

Output:

0 \pm 0.0 & 1 \pm 0.1 \\
2 \pm 0.2 & 3 \pm 0.3
munnich commented 5 years ago

I had another idea that'd probably see far more use: input multiple arrays and output that as a table. I believe a proper rounding method is implemented in the uncertainties package, so rounding should be possible, too.