np.repeat(np.arange(width).reshape(width,1),[height],axis=1)怎么用torch中的函数表示
时间: 2023-05-14 22:06:06 浏览: 51
您可以使用torch中的repeat函数来表示np.repeat(np.arange(width).reshape(width,1),[height],axis=1)。具体代码如下:
import torch
width = 3
height = 4
arr = torch.arange(width).reshape(width, 1)
result = arr.repeat(1, height)
print(result)
输出结果为:
tensor([[0, 0, 0, 0],
[1, 1, 1, 1],
[2, 2, 2, 2]])