__pow__#
- Rotation.__pow__(n, modulus=None)[source]#
Compose this rotation with itself n times.
Composition of a rotation
pwith itself can be extended to non-integernby considering the powernto be a scale factor applied to the angle of rotation about the rotation’s fixed axis. The expressionq = p ** ncan also be expressed asq = Rotation.from_rotvec(n * p.as_rotvec()).If
nis negative, then the rotation is inverted before the power is applied. In other words,p ** -abs(n) == p.inv() ** abs(n).- Parameters:
- nfloat | Array
The number of times to compose the rotation with itself. If n is an array, then it must be 0d or 1d with shape (1,).
- modulusNone
This overridden argument is not applicable to Rotations and must be
None.
- Returns:
- power
Rotationinstance The resulting rotation will be of the same shape as the original rotation object. Each element of the output is the corresponding element of the input rotation raised to the power of
n.
- power
Notes
For example, a power of 2 will double the angle of rotation, and a power of 0.5 will halve the angle. There are three notable cases: if
n == 1then the original rotation is returned, ifn == 0then the identity rotation is returned, and ifn == -1thenp.inv()is returned.Note that fractional powers
nwhich effectively take a root of rotation, do so using the shortest path smallest representation of that angle (the principal root). This means that powers ofnand1/nare not necessarily inverses of each other. For example, a 0.5 power of a +240 degree rotation will be calculated as the 0.5 power of a -120 degree rotation, with the result being a rotation of -60 rather than +120 degrees.Array API Standard Support
__pow__has experimental support for Python Array API Standard compatible backends in addition to NumPy. Please consider testing these features by setting an environment variableSCIPY_ARRAY_API=1and providing CuPy, PyTorch, JAX, or Dask arrays as array arguments. The following combinations of backend and device (or other capability) are supported.Library
CPU
GPU
NumPy
✅
n/a
CuPy
n/a
✅
PyTorch
✅
✅
JAX
✅
✅
Dask
⛔
n/a
See Support for the array API standard for more information.
Examples
>>> from scipy.spatial.transform import Rotation as R
Raising a rotation to a power:
>>> p = R.from_rotvec([1, 0, 0]) >>> q = p ** 2 >>> q.as_rotvec() array([2., 0., 0.]) >>> r = p ** 0.5 >>> r.as_rotvec() array([0.5, 0., 0.])
Inverse powers do not necessarily cancel out:
>>> p = R.from_rotvec([0, 0, 120], degrees=True) >>> ((p ** 2) ** 0.5).as_rotvec(degrees=True) array([ -0., -0., -60.])