[SciPy-user] Latex output with io.write_array

Pearu Peterson pearu at scipy.org
Tue Oct 7 02:27:29 EDT 2003



On Tue, 7 Oct 2003, Nils Wagner wrote:

> Dear experts,
> 
> Is it somehow possible to extent the output options of io.write_array
> It would be nice to have an \LaTex output, e.g.
> 
> from scipy import *
> from RandomArray import *
> file=open("latex.out",'w')
> A = rand(3,3)
> io.write_array(file,A,separator='&', linesep='\n', precision=5,
> keep_open=0)
> 
> 
> 9.70506e-01&7.53710e-01&3.78068e-01
> 1.16224e-01&4.41116e-01&9.08877e-01
> 5.99735e-01&4.20824e-01&8.19178e-01
> 
> I would like to have something like that
> 
> \left[\begin{array}{ccc}
> 9.70506e-01&7.53710e-01&3.78068e-01 \\
> 1.16224e-01&4.41116e-01&9.08877e-01 \\
> 5.99735e-01&4.20824e-01&8.19178e-01 
> \end{array}\right]
> 
> 
> Any suggestion ?

That's basic Python question:

file=open("latex.out",'w')
file.write('\left[\begin{array}{ccc}')
io.write_array(file,A,separator='&', linesep=' \\\\\n', 
precision=5,keep_open=1)
file.write('\end{array}\right]')

Pearu



More information about the SciPy-User mailing list