{ } Raw JSON

bundles / scipy latest / scipy / spatial / transform / _rotation / Rotation / mean

function

scipy.spatial.transform._rotation:Rotation.mean

source: /scipy/spatial/transform/_rotation.py :1997

Signature

def   mean ( self weights : ArrayLike | None = None axis : None | int | tuple[int, ...] = None )  →  Rotation

Summary

Get the mean of the rotations.

Extended Summary

The mean used is the chordal L2 mean (also called the projected or induced arithmetic mean) [1]. If A is a set of rotation matrices, then the mean M is the rotation matrix that minimizes the following loss function:

where 's are the weights corresponding to each matrix.

Parameters

weights : array_like shape (..., N), optional

Weights describing the relative importance of the rotations. If None (default), then all values in weights are assumed to be equal. If given, the shape of weights must be broadcastable to the rotation shape. Weights must be non-negative.

axis : None, int, or tuple of ints, optional

Axis or axes along which the means are computed. The default is to compute the mean of all rotations.

Returns

mean : `Rotation` instance

Single rotation containing the mean of the rotations in the current instance.

Notes

Array API Standard Support

mean has experimental support for Python Array API Standard compatible backends in addition to NumPy. Please consider testing these features by setting an environment variable SCIPY_ARRAY_API=1 and 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 dev-arrayapi for more information.

Examples

from scipy.spatial.transform import Rotation as R
r = R.from_euler('zyx', [[0, 0, 0],
                         [1, 0, 0],
                         [0, 1, 0],
                         [0, 0, 1]], degrees=True)
r.mean().as_euler('zyx', degrees=True)

Aliases

  • scipy.spatial.transform.Rotation.mean