Normal Distribution

102 views
Skip to first unread message

Santanu Sarkar

unread,
Feb 17, 2012, 4:52:57 AM2/17/12
to sage-s...@googlegroups.com
How to generate 1000 random integers which follow normal
distribution with mean 0 and variance 0.1?

Vegard Lima

unread,
Feb 17, 2012, 5:30:41 AM2/17/12
to sage-s...@googlegroups.com

You can do this with numpy:

sage: import numpy as np
sage: mu, sigma = 0, sqrt(0.1) # mean and standard deviation
sage: s = np.random.normal(mu, sigma, 1000)

Note that it takes std.deviation as input not variance.


Cheers,
--
Vegard

Goebbe

unread,
Feb 17, 2012, 5:07:32 AM2/17/12
to sage-support
Not sure what generating "integers" means, when drawing from a
normal,
but if you just want to draw random numbers, the following should do
it:

NV001 = RealDistribution('gaussian',sqrt(0.1)) #N(0,0.1) mean=0 std
dev = sqrt(0.1)
randomdraws = [NV001.get_random_element() for _ in range(1000)]

Santanu Sarkar

unread,
Feb 17, 2012, 6:40:02 AM2/17/12
to sage-s...@googlegroups.com
Thanks for the help.

> --
> To post to this group, send email to sage-s...@googlegroups.com
> To unsubscribe from this group, send email to sage-support...@googlegroups.com
> For more options, visit this group at http://groups.google.com/group/sage-support
> URL: http://www.sagemath.org

Reply all
Reply to author
Forward
0 new messages