Argument Functions and Coordinate Functions

Argument functions, when fed with a single xtensors.TensorLike object, return an XTensor instance with integer data representing the indices of the original tensor. An example is xtensors.argsmax(), which returns the indices where the maximum values occur:

\[x[i,j,k,l]\]
\[y = \mathrm{argsmax}(x, \mathrm{dim}=1,2)\]
\[y[i,l,m] = \mathrm{argsmax}(x[i,:,:,l])[m]\]

Similarly, coordinate functions return the coordinates associated with the axes of the original tensor.

class xtensors.ArgsFunction(*args, **kwargs)

Bases: Protocol

Argument function protocol

__call__(x: TensorLike, /, dim: List[str | int | Tuple[str, int] | HasDimName]) XTensor
Parameters:
  • x – target tensor

  • dim – target dimension(s)

Returns:

an XTensor of rank x.rank - len(dim) + 1

class xtensors.CoordsFunction(*args, **kwargs)

Bases: Protocol

Coordinate function protocol

__call__(x: Array | Sequence | float, /, dim: List[str | int | Tuple[str, int] | HasDimName], *, use_index_if_no_coord: bool = False) XTensor
Parameters:
  • x – target tensor

  • dim – target dimension(s)

  • use_index_if_no_coord – whether to use indices instead of coordinates are not specified

Returns:

an XTensor of rank x.rank - len(dim) + 1

xtensors.argsmax(x: TensorLike, /, dim: DimLike | DimsLike | None) XTensor

Return the indices where maxima occur.

xtensors.argsmin(x: TensorLike, /, dim: DimLike | DimsLike | None) XTensor

Return the indices where minima occur.

xtensors.nanargsmax(x: TensorLike, /, dim: DimLike | DimsLike | None) XTensor

Similar to argsmax(), but with nan ignored

xtensors.nanargsmin(x: TensorLike, /, dim: DimLike | DimsLike | None) XTensor

Similar to argsmin(), but with nan ignored

xtensors.coordsmax(x: TensorLike, /, dim: DimLike | DimsLike | None, *, use_index_if_no_coord: bool = False) XTensor

Return the coordinates where maxima occur

xtensors.coordsmin(x: TensorLike, /, dim: DimLike | DimsLike | None, *, use_index_if_no_coord: bool = False) XTensor

Return the coordinates where minima occur

xtensors.nancoordsmax(x: TensorLike, /, dim: DimLike | DimsLike | None, *, use_index_if_no_coord: bool = False) XTensor

Similar to coordsmax(), but with nan ignored

xtensors.nancoordsmin(x: TensorLike, /, dim: DimLike | DimsLike | None, *, use_index_if_no_coord: bool = False) XTensor

Similar to coordsmin(), but with nan ignored