SciPy

scipy.spatial.transform.Rotation.random

classmethod Rotation.random(num=None, random_state=None)[source]

Generate uniformly distributed rotations.

Parameters:
num : int or None, optional

Number of random rotations to generate. If None (default), then a single rotation is generated.

random_state : int, RandomState instance or None, optional

Accepts an int as a seed for the random generator or a RandomState object. If None (default), uses global np.random random state.

Returns:
random_rotation : Rotation instance

Contains a single rotation if num is None. Otherwise contains a stack of num rotations.

Examples

>>> from scipy.spatial.transform import Rotation as R

Sample a single rotation:

>>> R.random(random_state=1234).as_euler('zxy', degrees=True)
array([-110.5976185 ,   55.32758512,   76.3289269 ])

Sample a stack of rotations:

>>> R.random(5, random_state=1234).as_euler('zxy', degrees=True)
array([[-110.5976185 ,   55.32758512,   76.3289269 ],
       [ -91.59132005,  -14.3629884 ,  -93.91933182],
       [  25.23835501,   45.02035145, -121.67867086],
       [ -51.51414184,  -15.29022692, -172.46870023],
       [ -81.63376847,  -27.39521579,    2.60408416]])