bundles / scipy 1.17.1 / scipy / spatial / transform / _rotation / Rotation / apply
function
scipy.spatial.transform._rotation:Rotation.apply
Signature
def apply ( self , vectors : ArrayLike , inverse : bool = False ) → Array Summary
Apply this rotation to a set of vectors.
Extended Summary
If the original frame rotates to the final frame by this rotation, then its application to a vector can be seen in two ways:
As a projection of vector components expressed in the final frame to the original frame.
As the physical rotation of a vector being glued to the original frame as it rotates. In this case the vector components are expressed in the original frame before and after the rotation.
In terms of rotation matrices, this application is the same as self.as_matrix() @ vectors.
Parameters
vectors: array_like, shape (..., 3)Each
vectors[..., :]represents a vector in 3D space. The shape of rotations and shape of vectors given must follow standard numpy broadcasting rules: either one of them equals unity or they both equal each other.inverse: boolean, optionalIf True then the inverse of the rotation(s) is applied to the input vectors. Default is False.
Returns
rotated_vectors: ndarray, shape (..., 3)Result of applying rotation on input vectors. Shape is determined according to numpy broadcasting rules. I.e., the result will have the shape
np.broadcast_shapes(r.shape, v.shape[:-1]) + (3,)
Notes
Array API Standard Support
apply 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-arrayapifor more information.
Examples
from scipy.spatial.transform import Rotation as R import numpy as np✓
vector = np.array([1, 0, 0]) r = R.from_rotvec([0, 0, np.pi/2])✓
r.as_matrix() r.apply(vector)✗
r.apply(vector).shape
✓vectors = np.array([ [1, 0, 0], [1, 2, 3]]) r = R.from_rotvec([0, 0, np.pi/4])✓
r.as_matrix() r.apply(vectors)✗
r.apply(vectors).shape
✓r = R.from_rotvec([[0, 0, np.pi/4], [np.pi/2, 0, 0]]) vector = np.array([1,2,3])✓
r.as_matrix() r.apply(vector)✗
r.apply(vector).shape
✓r = R.from_euler('zxy', [ [0, 0, 90], [45, 30, 60]], degrees=True) vectors = [ [1, 2, 3], [1, 0, -1]]✓
r.apply(vectors)
✗r.apply(vectors).shape
✓r = R.from_rotvec(np.tile([0, 0, np.pi/4], (5, 1, 4, 1))) vectors = np.ones((3, 4, 3)) r.shape, vectors.shape r.apply(vectors).shape✓
r = R.from_euler('zxy', [ [0, 0, 90], [45, 30, 60]], degrees=True) vectors = [ [1, 2, 3], [1, 0, -1]]✓
r.apply(vectors, inverse=True)
✗Aliases
-
scipy.spatial.transform.Rotation.apply