lab.shaping module¶
-
lab.shaping.
concat
[source]¶ Concatenate tensors along an axis.
- Parameters
*elements (tensor) – Tensors to concatenate
axis (int, optional) – Axis along which to concatenate. Defaults to 0.
- Returns
Concatenation.
- Return type
tensor
-
lab.shaping.
concat2d
[source]¶ Concatenate tensors into a matrix.
- Parameters
*rows (list[list[tensor]]) – List of list of tensors, which form the rows of the matrix.
- Returns
Assembled matrix.
- Return type
tensor
-
lab.shaping.
diag
[source]¶ Take the diagonal of a matrix, or construct a diagonal matrix from its diagonal.
- Parameters
a (tensor) – Matrix or diagonal.
- Returns
Diagonal or matrix.
- Return type
tensor
-
lab.shaping.
expand_dims
[source]¶ Insert an empty axis.
- Parameters
a (tensor) – Tensor.
axis (int, optional) – Index of new axis. Defaults to 0.
- Returns
a with the new axis.
- Return type
tensor
-
lab.shaping.
flatten
[source]¶ Flatten a tensor.
- Parameters
a (tensor) – Tensor.
- Returns
Flattened tensor.
- Return type
tensor
-
lab.shaping.
isscalar
[source]¶ Check whether a tensor is a scalar.
- Parameters
a (tensor) – Tensor.
- Returns
True if a is a scalar, otherwise False.
- Return type
bool
-
lab.shaping.
length
[source]¶ Get the length of a tensor.
- Parameters
a (tensor) – Tensor.
- Returns
Length of a.
- Return type
int
-
lab.shaping.
rank
[source]¶ Get the shape of a tensor.
- Parameters
a (tensor) – Tensor.
- Returns
Rank of a.
- Return type
int
-
lab.shaping.
reshape
[source]¶ Reshape a tensor.
- Parameters
a (tensor) – Tensor to reshape.
*shape (shape) – New shape.
- Returns
Reshaped tensor.
- Return type
tensor
-
lab.shaping.
shape
[source]¶ Get the shape of a tensor.
- Parameters
a (tensor) – Tensor.
- Returns
Shape of a.
- Return type
object
-
lab.shaping.
size
¶ Alias for length.
-
lab.shaping.
squeeze
[source]¶ Remove all axes containing only a single element.
- Parameters
a (tensor) – Tensor.
- Returns
a without axes containing only a single element.
- Return type
tensor
-
lab.shaping.
stack
[source]¶ Concatenate tensors along a new axis.
- Parameters
*elements (tensor) – Tensors to stack.
axis (int, optional) – Index of new axis. Defaults to 0.
- Returns
Stacked tensors.
- Return type
tensor
-
lab.shaping.
take
[source]¶ Take particular elements along an axis.
- Parameters
a (tensor) – Tensor.
indices_or_mask (list) – List of indices or boolean indicating which elements to take. Must be rank 1.
axis (int, optional) – Axis along which to take indices. Defaults to 0.
- Returns
Selected subtensor.
- Return type
tensor
-
lab.shaping.
tile
[source]¶ Tile a tensor.
- Parameters
a (tensor) – Tensor to tile.
*repeats (shape) – Repetitions per dimension
- Returns
Tiled tensor.
- Return type
tensor
-
lab.shaping.
tril_to_vec
[source]¶ Construct a vector from a lower triangular matrix.
- Parameters
a (tensor) – Lower triangular matrix.
offset (int, optional) – Diagonal offset.
- Returns
Vector
- Return type
tensor
-
lab.shaping.
unstack
[source]¶ Unstack tensors along an axis.
- Parameters
a (list) – List of tensors.
axis (int, optional) – Index along which to unstack. Defaults to 0.
- Returns
List of tensors.
- Return type
list[tensor]