qml.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 and TensorFlow 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 = tf.constant([0.6, 0.1, 0.6])
>>> y = tf.Variable([0.1, 0.2, 0.3])
>>> z = np.array([5., 8., 101.])
>>> stack([x, y, z])
<tf.Tensor: shape=(3, 3), dtype=float32, numpy=
array([[6.00e-01, 1.00e-01, 6.00e-01],
       [1.00e-01, 2.00e-01, 3.00e-01],
       [5.00e+00, 8.00e+00, 1.01e+02]], dtype=float32)>

Contents

Using PennyLane

Release news

Development

API

Internals