Direct surface.py

From Werner KRAUTH

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