paddle. expand_as ( x, y, name=None ) [source]

Expand the input tensor x to the same shape as the input tensor y.

Both the number of dimensions of x and y must be less than or equal to 6, and the number of dimensions of y must be greather than or equal to that of x. The dimension to expand must have a value of 1.

  • x (Tensor) – The input tensor, its data type is bool, float32, float64, int32 or int64.

  • y (Tensor) – The input tensor that gives the shape to expand to.

  • name (str, optional) – The default value is None. Normally there is no need for user to set this property. For more information, please refer to Name.


A Tensor with the same shape as y. The data type is the same as x.

Return type

N-D Tensor


import paddle

data_x = paddle.to_tensor([1, 2, 3], 'int32')
data_y = paddle.to_tensor([[1, 2, 3], [4, 5, 6]], 'int32')
out = paddle.expand_as(data_x, data_y)
np_out = out.numpy()
# [[1, 2, 3], [1, 2, 3]]