mirror of
https://github.com/MartinThoma/LaTeX-examples.git
synced 2025-04-26 06:48:04 +02:00
csv-bivariate-normal-distribution: added
This commit is contained in:
parent
e7f5c73e2a
commit
47e4e3113a
5 changed files with 106 additions and 0 deletions
34
tikz/csv-bivariate-normal-distribution/create.py
Executable file
34
tikz/csv-bivariate-normal-distribution/create.py
Executable file
|
@ -0,0 +1,34 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""Create samples for bivariate distribution"""
|
||||
|
||||
from numpy.random import multivariate_normal, seed
|
||||
|
||||
|
||||
def create_data(n):
|
||||
means = [0.0, 0.0]
|
||||
cov = [[1.0, 0.7], [0.7, 4.0]]
|
||||
seed(0)
|
||||
samples = multivariate_normal(means, cov, n)
|
||||
with open("data.csv", "w") as f:
|
||||
f.write("x,y\n")
|
||||
for datapoint in samples:
|
||||
f.write("%0.4f,%0.4f\n" % tuple(datapoint))
|
||||
|
||||
|
||||
def get_parser():
|
||||
from argparse import ArgumentParser, ArgumentDefaultsHelpFormatter
|
||||
parser = ArgumentParser(description=__doc__,
|
||||
formatter_class=ArgumentDefaultsHelpFormatter)
|
||||
parser.add_argument("-n",
|
||||
dest="n",
|
||||
default=5000,
|
||||
type=int,
|
||||
help="Number of points to generate")
|
||||
return parser
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
args = get_parser().parse_args()
|
||||
create_data(args.n)
|
Loading…
Add table
Add a link
Reference in a new issue