qml.math.expand_dims

expand_dims(tensor, axis)[source]

Expand the shape of an array by adding a new dimension of size 1 at the specified axis location.

Warning

This function differs from np.expand_dims.

Parameters
  • tensor (tensor_like) – tensor to expand

  • axis (int) – location in the axes to place the new dimension

Returns

a tensor with the expanded shape

Return type

tensor_like

Example

>>> x = tf.Variable([3, 4])
>>> expand_dims(x, axis=1)
<tf.Tensor: shape=(2, 1), dtype=int32, numpy=
array([[3],
       [4]], dtype=int32)>