{ } Raw JSON

bundles / scipy 1.18.0 / scipy / spatial / transform / _rigid_transform / RigidTransform / mean

function

scipy.spatial.transform._rigid_transform:RigidTransform.mean

source: /scipy/spatial/transform/_rigid_transform.py:1034

Signature

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

Summary

Get the mean of the transforms.

Extended Summary

The mean of a set of transforms is the same as the mean of its rotation and translation components.

The mean used for the rotation component 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 transforms. If None (default), then all values in weights are assumed to be equal. If given, the shape of weights must be broadcastable to the transform 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 transforms.

Returns

mean : `RigidTransform` instance

Single transform containing the mean of the transforms in the current instance.

Examples

import numpy as np
from scipy.spatial.transform import RigidTransform as Tf
from scipy.spatial.transform import Rotation as R
rng = np.random.default_rng(seed=123)
✓
The mean of a set of transforms is the same as the mean of the translation and rotation components:
t = rng.random((4, 3))
r = R.random(4, rng=rng)
tf = Tf.from_components(t, r)
✓
tf.mean().as_matrix()
Tf.from_components(t.mean(axis=0), r.mean()).as_matrix()
✗
array([[ 0.61593, -0.74508,  0.25588,  0.66999],
       [-0.59354, -0.65247, -0.47117,  0.25482],
       [ 0.51801,  0.13834, -0.84411,  0.52429],
       [ 0.     ,  0.     ,  0.     ,  1.     ]])

Aliases

  • scipy.spatial.transform.RigidTransform.mean