giagrad.Tensor.permute#
- Tensor.permute(axes=None)[source]#
Returns a view of the original tensor with its
axes
permuted.permute
uses numpy.transpose, the following documentation is adapted.For a 1-D tensor, this returns an unchanged view of the original tensor, as a transposed vector is simply the same vector. To convert a 1-D tensor into a 2-D tensor vector, an additional dimension must be added, e.g., tensor.unsqueeze(axis=0) achieves this, as does Tensor[:, None].
For a 2-D tensor, this is the standard matrix transpose. For an n-D tensor, if axes are given, their order indicates how the axes are permuted (see Examples). If axes are not provided, then tensor.permute().shape == tensor.shape[::-1].
- Parameters:
axes¶ (tuple or list of ints, optional) – If specified, it must be a tuple or list which contains a permutation of [0,1,…,N-1] where N is the number of axes of the original tensor. The i’th axis of the returned tensor will correspond to the axis numbered
axes[i]
of the input. If not specified, defaults torange(tensor.ndim)[::-1]
, which reverses the order of the axes.
Examples
>>> t = Tensor.empty(1, 2, 3, 2, dtype=int).uniform(-5, 5) >>> t tensor: [[[[ 1 0] [-3 4] [ 3 3]] ... [[ 3 -4] [-3 1] [-2 3]]]]
Note that axes has the same lenght as
giagrad.Tensor.ndim
.>>> t.permute(axes=(1, 2, 3, 0)) tensor: [[[[ 1] [ 0]] ... [[-3] [ 4]] ... [[ 3] [ 3]]] ... ... [[[ 3] [-4]] ... [[-3] [ 1]] ... [[-2] [ 3]]]] fn: Permute(axes = (1, 2, 3, 0)) >>> t.permute(axes=(1, 2, 3, 0)).shape (2, 3, 2, 1)