Skip to content

Shape

XTensor methods that change rank, size, or axis order — reshaping, (un)squeezing, transposing/permuting, and broadcasting — carrying names along with the data.

Bases: ExtendedTensor

A tensor with named dimensions and, optionally, per-dimension coordinate labels -- an xarray-like DataArray over a live torch.Tensor.

  • Dimensions are named through names (self-managed in _axis_names, independent of PyTorch's experimental builtin named-tensor feature, so the class works even where that API has been removed).
  • Coordinates label the positions along a named dimension. They live in coords -- a mapping dim name -> labels -- keyed by dimension name, so they follow their dimension through reshaping/reordering with no positional bookkeeping. A labelled dimension must be named.
  • Axis descriptors may enrich a name with extra fields -- any custom key you like (type is the OME-NGFF convention shown in examples; orientation is the one field with built-in behaviour) -- passed as a dict in place of a bare name ({"name": "x", "type": "space"}). names stays the ergonomic view (bare names); axes returns the full descriptors. The extra fields live in _axis_meta, keyed by dimension name, so they follow the dimension like coordinates do.

Select by label with sel, by integer position with isel, or reach a single label by attribute (x.red).

Attributes

mT property

mT: Self

Transpose of the last two dimensions (names included).

Methods:

broadcast_to

broadcast_to(*args, **kwargs) -> XTensor

Name-aware torch.broadcast_to: behaves like torch.broadcast_to, but this tensor's names (and coordinates, where applicable) propagate onto the result. See torch.broadcast_to for the full numerical behaviour.

diagonal

diagonal(*args, **kwargs) -> XTensor

Name-aware torch.diagonal: behaves like torch.diagonal, but this tensor's names (and coordinates, where applicable) propagate onto the result. See torch.diagonal for the full numerical behaviour.

expand

expand(*args, **kwargs) -> XTensor

Name-aware torch.expand: behaves like torch.expand, but this tensor's names (and coordinates, where applicable) propagate onto the result. See torch.expand for the full numerical behaviour.

flatten

flatten(*args, **kwargs) -> XTensor

Name-aware torch.flatten: behaves like torch.flatten, but this tensor's names (and coordinates, where applicable) propagate onto the result. See torch.flatten for the full numerical behaviour.

moveaxis

moveaxis(*args, **kwargs) -> XTensor

Name-aware torch.moveaxis: behaves like torch.moveaxis, but this tensor's names (and coordinates, where applicable) propagate onto the result. See torch.moveaxis for the full numerical behaviour.

movedim

movedim(*args, **kwargs) -> XTensor

Name-aware torch.movedim: behaves like torch.movedim, but this tensor's names (and coordinates, where applicable) propagate onto the result. See torch.movedim for the full numerical behaviour.

permute

permute(*args, **kwargs) -> XTensor

Name-aware torch.permute: behaves like torch.permute, but this tensor's names (and coordinates, where applicable) propagate onto the result. See torch.permute for the full numerical behaviour.

reshape

reshape(*args, **kwargs) -> XTensor

Name-aware torch.reshape: behaves like torch.reshape, but this tensor's names (and coordinates, where applicable) propagate onto the result. See torch.reshape for the full numerical behaviour.

squeeze

squeeze(*args, **kwargs) -> XTensor

Name-aware torch.squeeze: behaves like torch.squeeze, but this tensor's names (and coordinates, where applicable) propagate onto the result. See torch.squeeze for the full numerical behaviour.

swapaxes

swapaxes(*args, **kwargs) -> XTensor

Name-aware torch.swapaxes: behaves like torch.swapaxes, but this tensor's names (and coordinates, where applicable) propagate onto the result. See torch.swapaxes for the full numerical behaviour.

swapdims

swapdims(*args, **kwargs) -> XTensor

Name-aware torch.swapdims: behaves like torch.swapdims, but this tensor's names (and coordinates, where applicable) propagate onto the result. See torch.swapdims for the full numerical behaviour.

transpose

transpose(*args, **kwargs) -> XTensor

Name-aware torch.transpose: behaves like torch.transpose, but this tensor's names (and coordinates, where applicable) propagate onto the result. See torch.transpose for the full numerical behaviour.

unflatten

unflatten(*args, **kwargs) -> XTensor

Name-aware torch.unflatten: behaves like torch.unflatten, but this tensor's names (and coordinates, where applicable) propagate onto the result. See torch.unflatten for the full numerical behaviour.

unsqueeze

unsqueeze(*args, **kwargs) -> XTensor

Name-aware torch.unsqueeze: behaves like torch.unsqueeze, but this tensor's names (and coordinates, where applicable) propagate onto the result. See torch.unsqueeze for the full numerical behaviour.

view

view(*args, **kwargs) -> XTensor

Name-aware torch.view: behaves like torch.view, but this tensor's names (and coordinates, where applicable) propagate onto the result. See torch.view for the full numerical behaviour.