Tensor API
- class xtensors.XTensor(data: Array, dims: Sequence[str | None] | None = None, coords: Sequence[Sequence[Any] | NDArray[Any] | None] | None = None)
A wrapper class of
np.ndarraythat attaches names to each axis. “axis” and “dimension” are synonyms in this context.- __init__(data: Array, dims: Sequence[str | None] | None = None, coords: Sequence[Sequence[Any] | NDArray[Any] | None] | None = None) None
- Parameters:
data – the underlying array object, accepts any object that implements the
__array__protocoldims – a sequence of strings specifying the names of each axis
coords – a sequence of 1D arrays specifying the coordinates of each axis
By default, each dimension has
Noneas both its name and coordinates.
- viewcopy() XTensor
- Returns:
a new
XTensorobject with the same underlyingdata. Useful when one wishes to attach different metadata to the same array.
- item() float
- Returns:
data.item()- Raises:
ValueErrorifdatais not scalar
- property dims: Tuple[str | None, ...]
A tuple of strings or None corresponding to each axis’s name.
- property coords: Tuple[NDArray[Any] | None, ...]
A tuple of
np.ndarrayor None corresponding to each axis’s coordinates.
- property shape: Tuple[int, ...]
A tuple of
int, same asdata.shape
- property rank: int
Number of axes, same as
data.ndim
- get_axis(dim: str | int | Tuple[str, int] | HasDimName) int
Performs an axis lookup with a
DimLikeobject- Returns:
an integer representing the resulting axis
- Raises:
TypeError if
dimis not a validDimLikeobject
- get_axes(dims: DimLike | DimsLike | None) List[int]
Performs multiple axis lookups
- Returns:
A list of axes (integers)
- set_dims(dims: Sequence[str | None] | None) None
Set axis names.
- set_dim(dim: DimLike, newdim: str | None) None
Set the name of a single axis.
- get_coord(dim: DimLike) NDArray | None
Return the coordinates of the given axis.
- Returns:
If the axis has coordinates, an
np.ndarrayis returned, elseNoneis returned.
- set_coords(coords: Sequence[Sequence[Any] | NDArray[Any] | None] | None) None
Set coordinates.
- set_coord(dim: DimLike, coord: Sequence[Any] | NDArray[Any] | None) None
Set the coordinates of a single axis.
- slc(dim: str | int | Tuple[str, int] | HasDimName, slc: slice) XTensor
- Returns:
A new XTensor object with
dimsliced byslice.
- get(dim: str | int | Tuple[str, int] | HasDimName, index: int) XTensor
- Returns:
A new XTensor object with
dimindexed byindex.