ActiveState Code

Recipe 576870: Creating fake data using numpy


Create a deliberately bad normal distribution for sample data - varying the badness, mean, standard deviation and range of results shown.

Python
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
from numpy.random import normal
from scipy.stats import norm as normStat


CRAZINESS = 0.1
MIN = 50 
MAX = 300
STEP = 5
AVG = 180
DEV = 40 
p = normStat(AVG, DEV).pdf

def noise():
    return 1 + CRAZINESS * normal(1)

for x in range(MIN, MAX, STEP):
    print str(x), "\t",   p(x) * noise()

Comments

  1. 1. At 9:23 a.m. on 7 aug 2009, tat.wright (the author) said:

    Data can be pasted directly into spreadsheets.

    On linux machines this can be done using

    python program.py | xclip

  2. 2. At 1:46 a.m. on 4 sep 2009, Nugroho Adi Pramono said:

    or using excellerator to save output into .xls format

Sign in to comment