expand¶
-
paddle.fluid.layers.nn.
expand
( x, expand_times, name=None ) [source] -
Warning: API “paddle.fluid.layers.nn.expand” is deprecated since 2.0.0, and will be removed in future versions. Please use “paddle.expand” instead.
- alias_main
-
paddle.expand :alias: paddle.expand,paddle.tensor.expand,paddle.tensor.manipulation.expand :old_api: paddle.fluid.layers.expand
This operation tiles
x
multiple times according to the parameterexpand_times
. The times number for each dimension ofx
is set by the parameterexpand_times
. The rank ofx
should be less than or equal to 6. Please note that size ofexpand_times
must be the same with X’s rank. Following is a using case:Input(X) is a 3-D tensor with shape [2, 3, 1]: [ [[1], [2], [3]], [[4], [5], [6]] ] Attr(expand_times): [1, 2, 2] Output(Out) is a 3-D tensor with shape [2, 6, 2]: [ [[1, 1], [2, 2], [3, 3], [1, 1], [2, 2], [3, 3]], [[4, 4], [5, 5], [6, 6], [4, 4], [5, 5], [6, 6]] ]
- Args:
-
x (Variable): A
Tensor
orLoDTensor
with dimension in [1, 6]. The data type isbool
,float32
,float64
orint32
. expand_times (list|tuple|Variable): The data type isint32
. Ifexpand_times
is a list or tuple, the elements ofit should be integers or Tensors with shape [1]. If
expand_times
is an Variable, it should be an 1-D Tensor. Expand times number for each dimension ofx
.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 .
- Returns:
-
Variable: A
Tensor
orLoDTensor
. The data type is same asx
. After expanding, size of each dimension of output is equal to the size of the corresponding dimension ofx
multiplying the corresponding value given byexpand_times
. - Raises:
-
TypeError: The type of
expand_times
must be list, tuple or Variable. ValueError: The elements ofexpand_times
cannot be negative. - Examples:
-
import paddle.fluid as fluid # example 1: data_1 = fluid.layers.fill_constant(shape=[2, 3, 1], dtype='int32', value=0) expanded_1 = fluid.layers.expand(data_1, expand_times=[1, 2, 2]) # the shape of expanded_1 is [2, 6, 2]. # example 2: data_2 = fluid.layers.fill_constant(shape=[12, 14], dtype="int32", value=3) expand_times = fluid.layers.fill_constant(shape=[2], dtype="int32", value=4) expanded_2 = fluid.layers.expand(data_2, expand_times=expand_times) # the shape of expanded_2 is [48, 56].