qml.math.flatten

flatten(tensor)[source]

Flattens an N-dimensional tensor to a 1-dimensional tensor.

Parameters

tensor (tensor_like) – tensor to flatten

Returns

the flattened tensor

Return type

tensor_like

Example

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