Direct surface.py

From Werner KRAUTH

Revision as of 21:59, 22 September 2015; view current revision
←Older revision | Newer revision→
Jump to: navigation, search

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

Description

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]

Version

See history for version information.

Personal tools