Direct surface.py
From Werner KRAUTH
(Difference between revisions)
| Revision as of 21:20, 22 September 2015 Werner (Talk | contribs) ← Previous diff |
Current revision Werner (Talk | contribs) |
||
| Line 1: | Line 1: | ||
| + | This page presents the program direct_surface.py, a direct-sampling algorithm for uniform points on the surface of a d-dimensional unit sphere | ||
| + | |||
| + | __FORCETOC__ | ||
| + | =Description= | ||
| + | |||
| + | =Program= | ||
| import random, math | import random, math | ||
| Line 7: | Line 13: | ||
| radius = math.sqrt(sum(x ** 2 for x in R)) | radius = math.sqrt(sum(x ** 2 for x in R)) | ||
| print [x / radius for x in R] | print [x / radius for x in R] | ||
| + | =Version= | ||
| + | See history for version information. | ||
| + | |||
| + | [[Category:Python]] | ||
| + | [[Category:Honnef_2015]] | ||
| + | [[Category:MOOC_SMAC]] | ||
Current revision
This page presents the program direct_surface.py, a direct-sampling algorithm for uniform points on the surface of a d-dimensional unit sphere
Contents |
[edit]
Description
[edit]
Program
import random, math
dimensions = 5
nsamples = 20
for sample in xrange(nsamples):
R = [random.gauss(0.0, 1.0) for d in xrange(dimensions)]
radius = math.sqrt(sum(x ** 2 for x in R))
print [x / radius for x in R]
[edit]
Version
See history for version information.
