paddle. view_as ( x, other, name=None ) [source]

View x with other’s shape.

Note that the output Tensor will share data with origin Tensor and doesn’t have a Tensor copy in dygraph mode.

  • x (Tensor) – An N-D Tensor. The data type is float32, float64, int32, int64 or bool

  • other (Tensor) – The result tensor has the same size as other.

  • name (str, optional) – Name for the operation (optional, default is None). For more information, please refer to Name.


Tensor, A viewed Tensor with the same shape as other.


>>> import paddle
>>> paddle.base.set_flags({"FLAGS_use_stride_kernel": True})

>>> x = paddle.rand([2, 4, 6], dtype="float32")
>>> y = paddle.rand([8, 6], dtype="float32")

>>> out = paddle.view_as(x, y)
>>> print(out.shape)
[8, 6]