scipy.spatial.transform.Rotation.

__getitem__#

Rotation.__getitem__()#

Extract rotation(s) at given index(es) from object.

Create a new Rotation instance containing a subset of rotations stored in this object.

Parameters:
indexerindex, slice, or index array

Specifies which rotation(s) to extract. A single indexer must be specified, i.e. as if indexing a 1 dimensional array or list.

Returns:
rotationRotation instance
Contains
  • a single rotation, if indexer is a single index

  • a stack of rotation(s), if indexer is a slice, or and index array.

Raises:
TypeError if the instance was created as a single rotation.

Examples

>>> from scipy.spatial.transform import Rotation as R
>>> rs = R.from_quat([
... [1, 1, 0, 0],
... [0, 1, 0, 1],
... [1, 1, -1, 0]])  # These quats are normalized
>>> rs.as_quat()
array([[ 0.70710678,  0.70710678,  0.        ,  0.        ],
       [ 0.        ,  0.70710678,  0.        ,  0.70710678],
       [ 0.57735027,  0.57735027, -0.57735027,  0.        ]])

Indexing using a single index:

>>> a = rs[0]
>>> a.as_quat()
array([0.70710678, 0.70710678, 0.        , 0.        ])

Array slicing:

>>> b = rs[1:3]
>>> b.as_quat()
array([[ 0.        ,  0.70710678,  0.        ,  0.70710678],
       [ 0.57735027,  0.57735027, -0.57735027,  0.        ]])

List comprehension to split each rotation into its own object:

>>> c = [r for r in rs]
>>> print([r.as_quat() for r in c])
[array([ 0.70710678,  0.70710678,  0.        ,  0.        ]),
 array([ 0.        ,  0.70710678,  0.        ,  0.70710678]),
 array([ 0.57735027,  0.57735027, -0.57735027,  0.        ])]

Concatenation of split rotations will recover the original object:

>>> R.concatenate([a, b]).as_quat()
array([[ 0.70710678,  0.70710678,  0.        ,  0.        ],
       [ 0.        ,  0.70710678,  0.        ,  0.70710678],
       [ 0.57735027,  0.57735027, -0.57735027,  0.        ]])