# scipy 1.18.1 (BSD-3-Clause), harvested by tools/harvest_corpus.py
=== input
Get the mean of the transforms.

        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:

        .. math::

            L(M) = \sum_{i = 1}^{n} w_i \lVert \mathbf{A}_i -
            \mathbf{M} \rVert^2 ,

        where :math:`w_i`'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.

        References
        ----------
        .. [1] Hartley, Richard, et al.,
                "Rotation Averaging", International Journal of Computer Vision
                103, 2013, pp. 267-305.

        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()
        array([[ 0.61593485, -0.74508342,  0.25588075,  0.66999034],
               [-0.59353615, -0.65246765, -0.47116962,  0.25481794],
               [ 0.51801458,  0.13833531, -0.84411151,  0.52429339],
               [0., 0., 0., 1.]])
        >>> Tf.from_components(t.mean(axis=0), r.mean()).as_matrix()
        array([[ 0.61593485, -0.74508342,  0.25588075,  0.66999034],
               [-0.59353615, -0.65246765, -0.47116962,  0.25481794],
               [ 0.51801458,  0.13833531, -0.84411151,  0.52429339],
               [0., 0., 0., 1.]])
        
=== parse numpydoc
short_description: 'Get the mean of the transforms.'
long_description: |
  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:
  
  .. math::
  
      L(M) = \sum_{i = 1}^{n} w_i \lVert \mathbf{A}_i -
      \mathbf{M} \rVert^2 ,
  
  where :math:`w_i`'s are the `weights` corresponding to each matrix.
blank_after_short_description: True
blank_after_long_description: True
style: numpydoc
- DocstringParam
  description: |
    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.
  kind: param
  key: 'param'
  arg_name: 'weights'
  type_name: 'array_like shape (..., N)'
  is_optional: True
  raw_type_name: 'array_like shape (..., N), optional'
- DocstringParam
  description: |
    Axis or axes along which the means are computed. The default is to
    compute the mean of all transforms.
  kind: param
  key: 'param'
  arg_name: 'axis'
  type_name: 'None, int, or tuple of ints'
  is_optional: True
  default: 'to'
  raw_type_name: 'None, int, or tuple of ints, optional'
- DocstringReturns
  description: |
    Single transform containing the mean of the transforms in the
    current instance.
  kind: returns
  key: 'returns'
  type_name: '`RigidTransform` instance'
  is_generator: False
  return_name: 'mean'
- DocstringMeta
  description: |
    .. [1] Hartley, Richard, et al.,
            "Rotation Averaging", International Journal of Computer Vision
            103, 2013, pp. 267-305.
  kind: text
  key: 'references'
  title: 'References'
- DocstringExample
  kind: examples
  key: 'examples'
  snippet: '>>> import numpy as np'
- DocstringExample
  kind: examples
  key: 'examples'
  snippet: '>>> from scipy.spatial.transform import RigidTransform as Tf'
- DocstringExample
  kind: examples
  key: 'examples'
  snippet: '>>> from scipy.spatial.transform import Rotation as R'
- DocstringExample
  kind: examples
  key: 'examples'
  snippet: '>>> rng = np.random.default_rng(seed=123)'
- DocstringExample
  description: |
    The mean of a set of transforms is the same as the mean of the
    translation and rotation components:
  kind: examples
  key: 'examples'
  snippet: '>>> t = rng.random((4, 3))'
- DocstringExample
  kind: examples
  key: 'examples'
  snippet: '>>> r = R.random(4, rng=rng)'
- DocstringExample
  kind: examples
  key: 'examples'
  snippet: '>>> tf = Tf.from_components(t, r)'
- DocstringExample
  kind: examples
  key: 'examples'
  snippet: |
    >>> tf.mean().as_matrix()
    array([[ 0.61593485, -0.74508342,  0.25588075,  0.66999034],
           [-0.59353615, -0.65246765, -0.47116962,  0.25481794],
           [ 0.51801458,  0.13833531, -0.84411151,  0.52429339],
           [0., 0., 0., 1.]])
- DocstringExample
  kind: examples
  key: 'examples'
  snippet: |
    >>> Tf.from_components(t.mean(axis=0), r.mean()).as_matrix()
    array([[ 0.61593485, -0.74508342,  0.25588075,  0.66999034],
           [-0.59353615, -0.65246765, -0.47116962,  0.25481794],
           [ 0.51801458,  0.13833531, -0.84411151,  0.52429339],
           [0., 0., 0., 1.]])
=== detect
numpydoc
=== compose numpydoc
Get the mean of the transforms.

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:

.. math::

    L(M) = \sum_{i = 1}^{n} w_i \lVert \mathbf{A}_i -
    \mathbf{M} \rVert^2 ,

where :math:`w_i`'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.

References
----------
.. [1] Hartley, Richard, et al.,
        "Rotation Averaging", International Journal of Computer Vision
        103, 2013, pp. 267-305.

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()
array([[ 0.61593485, -0.74508342,  0.25588075,  0.66999034],
       [-0.59353615, -0.65246765, -0.47116962,  0.25481794],
       [ 0.51801458,  0.13833531, -0.84411151,  0.52429339],
       [0., 0., 0., 1.]])
>>> Tf.from_components(t.mean(axis=0), r.mean()).as_matrix()
array([[ 0.61593485, -0.74508342,  0.25588075,  0.66999034],
       [-0.59353615, -0.65246765, -0.47116962,  0.25481794],
       [ 0.51801458,  0.13833531, -0.84411151,  0.52429339],
       [0., 0., 0., 1.]])
