{ } Raw JSON

bundles / scipy 1.17.1 / scipy / spatial / transform / _rotation / Rotation / __getitem__

function

scipy.spatial.transform._rotation:Rotation.__getitem__

source: /scipy/spatial/transform/_rotation.py :2148

Signature

def   __getitem__ ( self indexer : int | slice | EllipsisType | 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.

Notes

Array API Standard Support

__getitem__ 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                   ⚠️ no JIT             ⚠️ no JIT           
Dask                  ⛔                     n/a                 
====================  ====================  ====================

See dev-arrayapi for more information.

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()
Indexing using a single index:
a = rs[0]
a.as_quat()
Array slicing:
b = rs[1:3]
b.as_quat()
List comprehension to split each rotation into its own object:
c = [r for r in rs]
print([r.as_quat() for r in c])
Concatenation of split rotations will recover the original object:
R.concatenate([a, b]).as_quat()

Aliases

  • scipy.spatial.transform.Rotation.__getitem__