Posts tagged ‘normal distribution’

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 likes LaTeX and Python, sometimes even combined. Do you like my content and would like to thank me for it? Consider making a small donation to my local fablab, the Dingfabrik Köln. Details on how to donate can be found here Spenden für die Dingfabrik.

More Posts - Website