differential_geometry.dense_utils.dense_permute_tensor_indices#
- differential_geometry.dense_utils.dense_permute_tensor_indices(tensor_field: ndarray, permutation: List[int], rank: int) ndarray [source]#
Permutes the order of the tensor indices in the last rank dimensions of the tensor field.
- Parameters:
tensor_field (
numpy.ndarray
) – Input tensor with shape (…, i₁, …, i_r), where the last rank axes are tensor indices.permutation (
list
ofint
) – Permutation to apply to the tensor indices. Must be of length rank and contain a permutation of [0, …, rank-1].rank (
int
) – The rank (number of tensor axes) of the tensor.
- Returns:
Tensor field with permuted tensor indices.
- Return type:
- Raises:
ValueError – If permutation is not valid.
Examples
>>> import numpy as np >>> T = np.random.rand(4, 4, 3, 3) >>> permute_tensor_indices(T, [1, 0], rank=2).shape (4, 4, 3, 3)