This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
def find_runs(x): | |
"""Find runs of consecutive items in an array.""" | |
# ensure array | |
x = np.asanyarray(x) | |
if x.ndim != 1: | |
raise ValueError('only 1D array supported') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def random_three_vector(): | |
""" | |
Generates a random 3D unit vector (direction) with a uniform spherical distribution | |
Algo from http://stackoverflow.com/questions/5408276/python-uniform-spherical-distribution | |
:return: | |
""" | |
phi = np.random.uniform(0,np.pi*2) | |
costheta = np.random.uniform(-1,1) | |
theta = np.arccos( costheta ) |