as_matrix#
- Rotation.as_matrix()[source]#
Represent as rotation matrix.
3D rotations can be represented using rotation matrices, which are 3 x 3 real orthogonal matrices with determinant equal to +1 [1].
- Returns:
- matrixndarray, shape (3, 3) or (N, 3, 3)
Shape depends on shape of inputs used for initialization.
Notes
This function was called as_dcm before.
Added in version 1.4.0.
Array API Standard Support
as_matrix
has experimental support for Python Array API Standard compatible backends in addition to NumPy. Please consider testing these features by setting an environment variableSCIPY_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 Support for the array API standard for more information.
References
Examples
>>> from scipy.spatial.transform import Rotation as R >>> import numpy as np
Represent a single rotation:
>>> r = R.from_rotvec([0, 0, np.pi/2]) >>> r.as_matrix() array([[ 2.22044605e-16, -1.00000000e+00, 0.00000000e+00], [ 1.00000000e+00, 2.22044605e-16, 0.00000000e+00], [ 0.00000000e+00, 0.00000000e+00, 1.00000000e+00]]) >>> r.as_matrix().shape (3, 3)
Represent a stack with a single rotation:
>>> r = R.from_quat([[1, 1, 0, 0]]) >>> r.as_matrix() array([[[ 0., 1., 0.], [ 1., 0., 0.], [ 0., 0., -1.]]]) >>> r.as_matrix().shape (1, 3, 3)
Represent multiple rotations:
>>> r = R.from_rotvec([[np.pi/2, 0, 0], [0, 0, np.pi/2]]) >>> r.as_matrix() array([[[ 1.00000000e+00, 0.00000000e+00, 0.00000000e+00], [ 0.00000000e+00, 2.22044605e-16, -1.00000000e+00], [ 0.00000000e+00, 1.00000000e+00, 2.22044605e-16]], [[ 2.22044605e-16, -1.00000000e+00, 0.00000000e+00], [ 1.00000000e+00, 2.22044605e-16, 0.00000000e+00], [ 0.00000000e+00, 0.00000000e+00, 1.00000000e+00]]]) >>> r.as_matrix().shape (2, 3, 3)