File size: 308 Bytes
5013cf3 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
import numpy as np
def point_on_hypersphere(n, theta):
"""Unit vector on n-sphere using angle theta in first two dimensions."""
v = np.zeros(n)
v[0] = np.cos(theta)
v[1] = np.sin(theta)
return v
def normalize(v):
norm = np.linalg.norm(v)
return v if norm < 1e-12 else v / norm
|