qml.math.reshape¶

reshape(tensor, shape)[source]

Gives a new shape to a tensor without changing its data.

Parameters
• tensor (tensor_like) – input tensor

• shape (tuple[int]) – The new shape. The special value of -1 indicates that the size of that dimension is computed so that the total size remains constant. A dimension of -1 can only be specified once.

Returns

a new view into the input tensor with shape shape

Return type

tensor_like

Example

>>> a = tf.range(4.)
>>> reshape(a, (2, 2))
<tf.Tensor: shape=(2, 2), dtype=float32, numpy=
array([[0., 1.],
[2., 3.]], dtype=float32)>
>>> b = torch.tensor([[0, 1], [2, 3]])
>>> torch.reshape(b, (-1,))
tensor([0, 1, 2, 3])