This is a pre-release version (2.0.0.dev0+git20260907.41eeb59).Go to latest (1.18.0)
{ } Raw JSON

bundles / scipy 2.0.0.dev0+git20260907.41eeb59 / scipy / spatial / transform / _rotation / Rotation / __getitem__

function

scipy.spatial.transform._rotation:Rotation.__getitem__

source: build-install/usr/lib/python3.14/site-packages/scipy/spatial/transform/_rotation.py:2155

Signature

def __getitem__(self, indexer: int | slice | EllipsisType | Array | None) → Rotation

Summary

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

Extended Summary

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

Parameters

indexer : index, 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

rotation : `Rotation` 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.70711,  0.70711,  0.     ,  0.     ],
       [ 0.     ,  0.70711,  0.     ,  0.70711],
       [ 0.57735,  0.57735, -0.57735,  0.     ]])
Indexing using a single index:
a = rs[0]
✓
a.as_quat()
✗
array([0.70711, 0.70711, 0.     , 0.     ])
Array slicing:
b = rs[1:3]
✓
b.as_quat()
✗
array([[ 0.     ,  0.70711,  0.     ,  0.70711],
       [ 0.57735,  0.57735, -0.57735,  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.70711, 0.70711, 0.     , 0.     ]), array([0.     , 0.70711, 0.     , 0.70711]), array([ 0.57735,  0.57735, -0.57735,  0.     ])]
Concatenation of split rotations will recover the original object:
R.concatenate([a, b]).as_quat()
✗
array([[ 0.70711,  0.70711,  0.     ,  0.     ],
       [ 0.     ,  0.70711,  0.     ,  0.70711],
       [ 0.57735,  0.57735, -0.57735,  0.     ]])

Aliases

  • scipy.spatial.transform.Rotation.__getitem__