{ } Raw JSON

bundles / scipy 1.18.0 / scipy / spatial / transform / _rigid_transform / RigidTransform / __len__

function

scipy.spatial.transform._rigid_transform:RigidTransform.__len__

source: /scipy/spatial/transform/_rigid_transform.py:1290

Signature

def __len__(self) → int

Summary

Return the length of the leading transform dimension.

Extended Summary

A transform can store an N-dimensional array of transforms. The length is the size of the first dimension of this array. If the transform is a single transform, the length is not defined and an error is raised.

Returns

length : int

The number of transforms in this object.

Raises

: TypeError

If the transform is a single transform.

Examples

from scipy.spatial.transform import RigidTransform as Tf
import numpy as np
tf = Tf.identity(3)
len(tf)
✓
3
An N-dimensional array of transforms returns its first dimension size:
t = np.ones((5, 2, 3, 1, 3))
tf = Tf.from_translation(t)
len(tf)
✓
5
A single transform has no length:
tf = Tf.from_translation([1, 0, 0])
len(tf)  # doctest: +IGNORE_EXCEPTION_DETAIL
✓
Traceback (most recent call last):
  File "<doctest scipy.spatial.transform._rigid_transform:RigidTransform.__len__[0]>", line 1, in <module>
    len(tf)  # doctest: +IGNORE_EXCEPTION_DETAIL
    ~~~^^^^
  File "/opt/hostedtoolcache/Python/3.14.7/x64/lib/python3.14/site-packages/scipy/spatial/transform/_rigid_transform.py", line 1333, in __len__
    raise TypeError("Single transform has no len")
TypeError: Single transform has no len

Aliases

  • scipy.spatial.transform.RigidTransform.__len__