{ } Raw JSON

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

function

scipy.spatial.transform._rotation:Rotation.__mul__

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

Signature

def   __mul__ ( self other : Rotation )  →  Rotation | NotImplementedType

Summary

Compose this rotation with the other.

Extended Summary

If p and q are two rotations, then the composition of 'q followed by p' is equivalent to p * q. In terms of rotation matrices, the composition can be expressed as p.as_matrix() @ q.as_matrix().

Parameters

other : `Rotation` instance

Object containing the rotations to be composed with this one. Note that rotation compositions are not commutative, so p * q is generally different from q * p.

Returns

composition : `Rotation` instance

This function supports composition of multiple rotations at a time. Composition follows standard numpy broadcasting rules. The resulting Rotation object will have the shape np.broadcast_shapes(p.shape, q.shape). In dimensions with size > 1, rotations are composed with matching indices. In dimensions with only one rotation, the single rotation is composed with each rotation in the other object.

Notes

Array API Standard Support

__mul__ 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
import numpy as np
Composition of two single rotations:
p = R.from_quat([0, 0, 1, 1])
q = R.from_quat([1, 0, 0, 1])
p.as_matrix()
q.as_matrix()
r = p * q
r.as_matrix()
Composition of two objects containing equal number of rotations:
p = R.from_quat([[0, 0, 1, 1], [1, 0, 0, 1]])
q = R.from_rotvec([[np.pi/4, 0, 0], [-np.pi/4, 0, np.pi/4]])
p.as_quat()
q.as_quat()
r = p * q
r.as_quat()
Broadcasting rules apply:
p = R.from_quat(np.tile(np.array([0, 0, 1, 1]), (5, 1, 1)))
q = R.from_quat(np.tile(np.array([1, 0, 0, 1]), (1, 6, 1)))
p.shape, q.shape
r = p * q
r.shape

Aliases

  • scipy.spatial.transform.Rotation.__mul__