numpy.tile(A, reps)
Parameters:
A : The input array.
reps : The number of repetitions of A along each axis
import torch
import numpy as np
x = torch.from_numpy(np.arange(4).reshape((1, 4)))
print('tensor原型:', x)
print('x沿着维度0复制2倍', np.tile(x, 2))
print('x沿着维度0、维度1,分别复制2倍、2倍', np.tile(x, (2, 2)))
print('x沿着维度0、维度1、维度2,分别复制2倍、2倍、2倍', np.tile(x, (2, 2, 2)))
代码运行结果:
tensor原型: tensor([[0, 1, 2, 3]])
x沿着维度0复制2倍 [[0 1 2 3 0 1 2 3]]
x沿着维度0、维度1,分别复制2倍、2倍 [[0 1 2 3 0 1 2 3]
[0 1 2 3 0 1 2 3]]
x沿着维度0、维度1、维度2,分别复制2倍、2倍、2倍 [[[0 1 2 3 0 1 2 3]
[0 1 2 3 0 1 2 3]]
[[0 1 2 3 0 1 2 3]
[0 1 2 3 0 1 2 3]]]

本文介绍了如何使用numpy库中的tile函数沿不同维度复制张量。通过实例演示了如何将一维张量沿多个维度进行复制,展示了tile函数在处理多维数据时的强大功能。
551

被折叠的 条评论
为什么被折叠?



