Tensor Utilities
- xtensors.permute(X: TensorLike, axes: AxesPermutation) XTensor
Permute the axes of
X- Parameters:
X – target tensor
axes – An
AxesPermutation(list of integers) object that specifies how the axes should be permuted.
- xtensors.newdims(X: TensorLike, *, dims: Dims | None = None, coords: Coords | None = None, position: Literal['left', 'right'] = 'left') XTensor
Pad singleton dimensions to the given tensor with the specified dimension names and coordinates.
- Parameters:
X – target tensor
dims – (optional,
xtensors.Dims) a list of strings specifying the new dimension namescoords – (optional,
xtensors.Coords) a list of arrays specifying the new coordinatesposition –
leftorright, where the new dimensions are padded
- xtensors.align(X: TensorLike, Y: TensorLike) Tuple[XTensor, XTensor]
Pad singleton unnamed dimensions to (at most) one of the two tensors so that the returned tensors have the same number of dimnesions.
- xtensors.stack(x: Sequence[XTensor], newdim: str | None = None, position: Literal['left', 'right'] = 'left') XTensor
Stack a sequence of tensors along a new axis
- Parameters:
x – sequence of tensors
newdim – the name of the new dimension
position –
leftorright, where the new dimension is padded
- xtensors.index(X: XTensor, *indices: Tuple[DimLike, int], ignore_if_absent: bool = False) XTensor
Index a tensor on multiple dimensions
- Parameters:
X – target tensor
indices – a series of (dim, index) pairs
ignore_if_absent – if
True, dimension names that are specified but not found inXwill be ignored without raising errors.
- xtensors.dimslast(X: XTensor, dims: Sequence[str]) XTensor
Move named dimensions to the right.
- Parameters:
X – target tensor
dims – a sequence of dimension names
- Returns:
a new
xtensors.XTensorwithdimsmoved to the right.
- xtensors.dimsfirst(X: XTensor, dims: Sequence[str]) XTensor
Move named dimensions to the left.
- Parameters:
X – target tensor
dims – a sequence of dimension names
- Returns:
a new
xtensors.XTensorwithdimsmoved to the left
- xtensors.flatten(X: TensorLike, /, dims: DimsLike, dim_out: str | None, *, position: Literal['left', 'right'] = 'right') XTensor
Flatten a tensor
- Parameters:
X – target tensor
dims – dimensions to be flattened
dim_out – name of the new dimension
position –
leftorright, where the new dimension is placed
- xtensors.name_dim_if_absent(X: TensorLike, /, axis: int, dim: str, *, force: bool = False) XTensor
Ensure that
Xhas a named dimension calleddim. If not already, the dimension ataxiswill be named so.- Parameters:
X – target tensor
axis – the axis to be renamed
dim – axis name
force – if
True, original axis name will be overwritten