Generating a normal distribution table with SciPy

Here’s a simple example how one can generate a normal distribution table with Python and scipy so that it can be imported into LaTeX.

# -*- coding: utf-8 -*-
Created on Mon Mar 13 21:14:17 2017
@author: Uwe Ziegenhagen,
Creates a CDF table for the standard normal distribution
use booktabs package in the preamble and put 
the generated numbers inside (use only one backslash!)
\\begin{tabular}{r|cccccccccc} \\toprule
<output here>
from scipy.stats import norm
horizontal = range(0,10,1)
vertikal = range(0,37)
header = ''
for i in horizontal:
    header = header + '& ' + str(i/100)
print(header, '\\\\ \\midrule')
for j in vertikal:  
    x = j/10
    print('\\\\', x)
    for i in horizontal:
        y = x + i/100
        print('& ', "{:10.4f}".format(norm.cdf(y),4))
print('\\\\ \\bottomrule \r\n')


Uwe Ziegenhagen has been working with LaTeX for more than a decade. Besides TeX/LaTeX he likes to work with Python, Rasberry/Arduino and his digital camera.

More Posts - Website