Tensor

class btensor.tensor.Tensor(data, basis=None, variance=None, name=None, numpy_compatible=True, copy_data=True)[source]

A numerical container class with support for automatic basis transformation.

Parameters
  • data (ArrayLike) – NumPy array containing the representation of the tensor.

  • basis (NBasis | None) – Basis object or tuple of Basis objects, representing the Basis along each axis of the input data. Default: nobasis along each axis.

  • variance (Sequence[int] | None) – Variance along each dimension. Default: -1.

  • name (str | None) – Name of the tensor. Default: ‘Basis<ID>’ where <ID> is the ID of the basis.

  • numpy_compatible (bool) – If True, the tensor can be used in standard NumPy function calls. The basis of the tensor will however not be taken into consideration and no automatic basis transformations will be performed. Default: True.

  • copy_data (bool) – If False, no copy of the NumPy data will be created. Default: True.

Return type

None

Methods

__init__

Create new Tensor instance.

change_basis

Change basis of tensor.

change_basis_at

Change basis of tensor along one or more selected axes.

change_variance

Change variance of tensor and transform representation accordingly.

change_variance_at

Change variance of tensor along a single axis and transform representation accordingly.

copy

Create a copy of the tensor.

dot

Dot product of two tensors.

get_common_basis

Get tuple of common bases between two tensors along each axis.

is_compatible

Check if the basis of the tensor is compatible with another tensor's basis along each axis.

project

Transforms tensor to a different set of basis.

replace_basis

Replace basis of tensor with a new basis.

replace_variance

Replace variance of tensor without corresponding transformation of the representation.

sum

Sum of tensor elements over a given axis or tuple of axes.

to_numpy

Get representation of tensor as a NumPy ndarray.

trace

Returns the sum along diagonals of the tensor.

transpose

Return a tensor with axes transposed.

Attributes

T

Transposed tensor.

basis

Basis of the tensor.

cob

Change of basis interface, similar to change_basis, but using []-syntax.

dtype

NumPy's dtype of the underlying ndarray.

ndim

Number of dimensions of the tensor.

numpy_compatible

shape

Current shape of the tensor.

variance

Tuple with ndim elements with value 1 or -1, for covariance and contravariance, respectively.