paddle.tile()函数的用法

定义:

paddle.tile(xrepeat_timesname=None);根据参数 repeat_times 对输入 x 的各维度进行复制。

返回值:

Tensor,数据类型与 x 相同。返回值的第 i 维的大小等于 x[i] * repeat_times[i] 。

比如:
data = paddle.to_tensor([1, 2, 3], dtype='int32')

out = paddle.tile(data, repeat_times=[2, 1])

复制前:data.shape=1 * 3;

复制后:new_data[0].shape= 1 * 2=2 ; new_data[1].shape=3 * 1=3

new_data.shape=2 *3;

举例子:

import paddle

data = paddle.to_tensor([1, 2, 3], dtype='int32')
print("复制前:",data.shape)
out = paddle.tile(data, repeat_times=[2, 1]) #一共是两行,每行只复制一次[1,2,3];
print(out)
print("复制后:",out.shape) 
# 复制前: [3]
# Tensor(shape=[2, 3], dtype=int32, place=Place(cpu), stop_gradient=True,
#        [[1, 2, 3],
#         [1, 2, 3]])
# 复制后: [2, 3]  #(1*2=2,3*1=3)





out = paddle.tile(data, repeat_times=(2, 2))#一共是两行,每行复制两次[1,2,3];
print(out)
print("复制后:",out.shape) 
# Tensor(shape=[2, 6], dtype=int32, place=Place(cpu), stop_gradient=True,
#        [[1, 2, 3, 1, 2, 3],
#         [1, 2, 3, 1, 2, 3]])
# 复制后: [2, 6] #(1*2=2 ,3*2=6)



repeat_times = paddle.to_tensor([1, 2], dtype='int32') #一共是一行,然后复制两次[1,2,3]
out = paddle.tile(data, repeat_times=repeat_times)
print(out)
print("复制后:",out.shape)

# Tensor(shape=[1, 6], dtype=int32, place=Place(cpu), stop_gradient=True,
#        [[1, 2, 3, 1, 2, 3]])
# 复制后: [1, 6]  #(1*1=1, 3*2=6)

你可能感兴趣的:(深度学习,paddle)