ravel

paddle. ravel ( input: Tensor ) Tensor [source]

Return a contiguous flattened tensor. A copy is made only if needed. .. note:

The output Tensor will share data with origin Tensor and doesn't have a Tensor copy in ``dygraph`` mode.
If you want to use the Tensor copy version, please use `Tensor.clone` like ``ravel_clone_x = x.ravel().clone()``.
For example:

.. code-block:: text
    Case 1:
      Given
        X.shape = (3, 100, 100, 4)

      We get:
        Out.shape = (3 * 100 * 100 * 4)
Parameters

x (Tensor) – A tensor of number of dimensions >= axis. A tensor with data type float16, float32, float64, int8, int32, int64, uint8.

Returns

A tensor with the contents of the input tensor, whose input axes are flattened by indicated start_axis and stop_axis, and data type is the same as input x.

Return type

Tensor

Examples

>>> import paddle

>>> image_shape=(2, 3, 4, 4)

>>> x = paddle.arange(end=image_shape[0] * image_shape[1] * image_shape[2] * image_shape[3])
>>> img = paddle.reshape(x, image_shape)

>>> out = paddle.ravel(img)
>>> print(out.shape)
[96]