Skip to main content
`Ctrl`+`K`
scipy.spatial.transform.RigidTransform.

# identity

static RigidTransform.identity(num=None, *, shape=None)

  Initialize an identity transform.

  Composition with the identity transform has no effect, and applying the identity transform to a vector has no effect.

  Parameters:
    num int, optional

      Number of identity transforms to generate. If None (default), then a single transform is generated.

    shape int or tuple of ints, optional

      Shape of the identity transforms. If specified, num must be None.

  Returns:
    transform `RigidTransform` instance

      The identity transform.

  Notes

  Array API Standard Support

  `identity` 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 | ✅ | ✅
  Dask | ⛔ | n/a

  > See Support for the array API standard for more information.

  Examples

      >>> from scipy.spatial.transform import RigidTransform as Tf
      >>> from scipy.spatial.transform import Rotation as R
      >>> import numpy as np

  Creating a single identity transform:

      >>> tf = Tf.identity()
      >>> tf.as_matrix()
      array([[1., 0., 0., 0.],
             [0., 1., 0., 0.],
             [0., 0., 1., 0.],
             [0., 0., 0., 1.]])
      >>> tf.single
      True

  The identity transform can be applied to a vector without effect:

      >>> tf.apply([1, 2, 3])
      array([1., 2., 3.])

  The identity transform when composed with another transform has no effect:

      >>> rng = np.random.default_rng()
      >>> t = rng.random(3)
      >>> r = R.random(rng=rng)
      >>> tf = Tf.from_components(t, r)
      >>> np.allclose((Tf.identity() * tf).as_matrix(),
      ...             tf.as_matrix(), atol=1e-12)
      True

  Multiple identity transforms can be generated at once:

      >>> tf = Tf.identity(2)
      >>> tf.as_matrix()
      array([[[1., 0., 0., 0.],
              [0., 1., 0., 0.],
              [0., 0., 1., 0.],
              [0., 0., 0., 1.]],
             [[1., 0., 0., 0.],
              [0., 1., 0., 0.],
              [0., 0., 1., 0.],
              [0., 0., 0., 1.]]])
      >>> tf.single
      False
      >>> len(tf)
      2