new style for numpy random numbers
https://numpy.org/doc/stable/reference/random/index.html?highlight=random#quick-start https://albertcthomas.github.io/good-practices-random-number-generators/
This commit is contained in:
parent
77026e5d53
commit
82e41d92ce
|
@ -613,13 +613,29 @@ class Rotation:
|
||||||
return Rotation.from_quaternion(np.real(vec.T[eig.argmax()]),accept_homomorph = True)
|
return Rotation.from_quaternion(np.real(vec.T[eig.argmax()]),accept_homomorph = True)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def from_random(shape=None):
|
def from_random(shape=None,seed=None):
|
||||||
|
"""
|
||||||
|
Draw random rotation.
|
||||||
|
|
||||||
|
Rotations are uniformly distributed.
|
||||||
|
|
||||||
|
Parameters
|
||||||
|
----------
|
||||||
|
shape : tuple of ints, optional
|
||||||
|
Shape of the sample. Defaults to None which gives a
|
||||||
|
single rotation
|
||||||
|
seed : {None, int, array_like[ints], SeedSequence, BitGenerator, Generator}, optional
|
||||||
|
A seed to initialize the BitGenerator. Defaults to None.
|
||||||
|
If None, then fresh, unpredictable entropy will be pulled from the OS.
|
||||||
|
|
||||||
|
"""
|
||||||
|
rng = np.random.default_rng(seed)
|
||||||
if shape is None:
|
if shape is None:
|
||||||
r = np.random.random(3)
|
r = rng.random(3)
|
||||||
elif hasattr(shape, '__iter__'):
|
elif hasattr(shape, '__iter__'):
|
||||||
r = np.random.random(tuple(shape)+(3,))
|
r = rng.random(tuple(shape)+(3,))
|
||||||
else:
|
else:
|
||||||
r = np.random.rand(shape,3)
|
r = rng.random((shape,3))
|
||||||
|
|
||||||
A = np.sqrt(r[...,2])
|
A = np.sqrt(r[...,2])
|
||||||
B = np.sqrt(1.0-r[...,2])
|
B = np.sqrt(1.0-r[...,2])
|
||||||
|
|
Loading…
Reference in New Issue