bundles / scipy 2.0.0.dev0+git20260907.41eeb59 / scipy / spatial / transform / _rotation / Rotation / from_matrix
staticmethod
scipy.spatial.transform._rotation:Rotation.from_matrix
source: build-install/usr/lib/python3.14/site-packages/scipy/spatial/transform/_rotation.py:532
Signature
def from_matrix(matrix: ArrayLike, *, assume_valid: bool = False) → RotationSummary
Initialize from rotation matrix.
Extended Summary
Rotations in 3 dimensions can be represented with 3 x 3 orthogonal matrices [1]. If the input is not orthogonal, an approximation is created by orthogonalizing the input matrix using the method described in [2], and then converting the orthogonal rotation matrices to quaternions using the algorithm described in [3]. Matrices must be right-handed.
Parameters
matrix: array_like, shape (..., 3, 3)A single matrix or an ND array of matrices, where the last two dimensions contain the rotation matrices.
assume_valid: bool, optionalMust be False unless users can guarantee the input is a valid rotation matrix, i.e. it is orthogonal, rows and columns have unit norm and the determinant is 1. Setting this to True without ensuring these properties is unsafe and will silently lead to incorrect results. If True, normalization steps are skipped, which can improve runtime performance. Default is False.
Returns
rotation: `Rotation` instanceObject containing the rotations represented by the rotation matrices.
Notes
This function was called from_dcm before.
Examples
from scipy.spatial.transform import Rotation as R import numpy as np✓
r = R.from_matrix([ [0, -1, 0], [1, 0, 0], [0, 0, 1]]) r.single r.as_matrix().shape✓
(3, 3)Initialize multiple rotations in a single object:
r = R.from_matrix([ [ [0, -1, 0], [1, 0, 0], [0, 0, 1], ], [ [1, 0, 0], [0, 0, -1], [0, 1, 0], ]]) r.as_matrix().shape r.single len(r)✓
2If input matrices are not special orthogonal (orthogonal with determinant equal to +1), then a special orthogonal estimate is stored:
a = np.array([ [0, -0.5, 0], [0.5, 0, 0], [0, 0, 0.5]])✓
np.linalg.det(a)
✗np.float64(0.12500000000000003)
r = R.from_matrix(a) matrix = r.as_matrix() matrix✓
array([[ 0., -1., 0.],
[ 1., 0., 0.],
[ 0., 0., 1.]])
np.linalg.det(matrix)
✗np.float64(0.9999999999999993)It is also possible to have a stack containing a single rotation:
r = R.from_matrix([[ [0, -1, 0], [1, 0, 0], [0, 0, 1]]]) r.as_matrix() r.as_matrix().shape✓
(1, 3, 3)We can also create an N-dimensional array of rotations:
r = R.from_matrix(np.tile(np.eye(3), (2, 3, 1, 1))) r.shape✓
(2, 3)
Aliases
scipy.spatial.transform.Rotation.from_matrix