bundles / scipy 1.18.0 / scipy / spatial / transform / _rotation / Rotation / random
staticmethod
scipy.spatial.transform._rotation:Rotation.random
Signature
def random(num: int | None = None, rng: np.random.Generator | None = None, *, shape: tuple[int, ...] | None = None, random_state = None) → RotationSummary
Generate rotations that are uniformly distributed on a sphere.
Extended Summary
Formally, the rotations follow the Haar-uniform distribution over the SO(3) group.
Parameters
num: int or None, optionalNumber of random rotations to generate. If None (default), then a single rotation is generated.
rng: {None, int, `numpy.random.Generator`}, optionalIf
rngis passed by keyword, types other than numpy.random.Generator are passed to numpy.random.default_rng to instantiate aGenerator. Ifrngis already aGeneratorinstance, then the provided instance is used. Specifyrngfor repeatable function behavior.If this argument is passed by position or
random_stateis passed by keyword, legacy behavior for the argumentrandom_stateapplies:If
random_stateis None (or numpy.random), the numpy.random.RandomState singleton is used.If
random_stateis an int, a newRandomStateinstance is used, seeded withrandom_state.If
random_stateis already aGeneratororRandomStateinstance then that instance is used.
shape: tuple of ints, optionalShape of random rotations to generate. If specified,
nummust be None.
Returns
random_rotation: `Rotation` instanceContains a single rotation if
numis None. Otherwise contains a stack ofnumrotations.
Notes
This function is optimized for efficiently sampling random rotation matrices in three dimensions. For generating random rotation matrices in higher dimensions, see scipy.stats.special_ortho_group.
Examples
from scipy.spatial.transform import Rotation as R
✓R.random().as_euler('zxy', degrees=True)
✗array([51.86589, -7.59653, -8.07539])Sample a stack of rotations:
R.random(5).as_euler('zxy', degrees=True)
✗array([[ 172.19225, 31.80042, -147.99033],
[ 144.45433, -23.61466, 179.46657],
[ -67.72847, -16.92282, -54.72594],
[ -38.49567, -43.46968, 45.01377],
[ -79.23888, 50.44661, -127.61762]])
See also
- scipy.stats.special_ortho_group
Aliases
scipy.spatial.transform.Rotation.random