qp.math.stack

stack(values, axis=0, like=None)[source]

Stack a sequence of tensors along the specified axis.

Warning

Tensors that are incompatible (such as Torch tensors) cannot both be present.

Parameters:
  • values (Sequence[tensor_like]) – Sequence of tensor-like objects to stack. Each object in the sequence must have the same size in the given axis.

  • axis (int) – The axis along which the input tensors are stacked. axis=0 corresponds to vertical stacking.

Returns:

The stacked array. The stacked array will have one additional dimension compared to the unstacked tensors.

Return type:

tensor_like

Example

>>> x = torch.tensor([0.6, 0.1, 0.6])
>>> y = torch.tensor([0.1, 0.2, 0.3])
>>> z = np.array([5., 8., 101.])
>>> stack([x, y, z])
tensor([[6.0000e-01, 1.0000e-01, 6.0000e-01],
        [1.0000e-01, 2.0000e-01, 3.0000e-01],
        [5.0000e+00, 8.0000e+00, 1.0100e+02]], dtype=torch.float64)