Skip to content

Tensor.retag

Update tensor index tags.

retag

retag(
    mapping_or_axes: Union[
        Mapping[str, str], Sequence[str], int, Sequence[int]
    ],
    new_tags: Optional[Union[str, Sequence[str]]] = None,
) -> None

Retag indices using one of three modes.

Parameters:

Name Type Description Default
mapping_or_axes Union[Mapping[str, str], Sequence[str], int, Sequence[int]]

Can be one of:

  • Mapping[str, str]: Dictionary mapping old tags to new tags
  • Sequence[str]: Complete list of new tags (must match number of indices)
  • Sequence[int] or int: Index position(s) to update (requires new_tags)

required
new_tags Optional[Union[str, Sequence[str]]]

New tag(s) to use when mapping_or_axes is an integer or sequence of integers. Can be a single string or sequence of strings. Must match the length of mapping_or_axes.

None

Examples:

>>> # Mode 1: Mapping (update specific tags by name)
>>> tensor.retag({"a": "left", "b": "right"})
>>> 
>>> # Mode 2: Full replacement (replace all tags)
>>> tensor.retag(["left", "middle", "right"])
>>> 
>>> # Mode 3: Selective update by position
>>> tensor.retag([0, 2], ["left", "right"])
>>> tensor.retag(0, "left")  # Single index and tag

Description

Changes the tags (labels) of tensor indices. Can update specific tags by name or position, or replace all tags at once.

This is an in-place operation.

Usage Modes

  1. By keyword: retag(old_tag="new_tag")
  2. By sequence: retag(["tag1", "tag2", "tag3"])

See Also

Notes

Tags are used for automatic contraction matching. Changing tags doesn't affect tensor data, only metadata.