torch.
repeat_interleave
(input, repeats, dim=None) → Tensor
Repeat elements of a tensor.
Parameters
-
input (Tensor) – the input tensor.
-
repeats (Tensor or int) – The number of repetitions for each element. repeats is broadcasted to fit the shape of the given axis.
-
dim (int, optional) – The dimension along which to repeat values. By default, use the flattened input array, and return a flat output array.
Returns
Repeated tensor which has the same shape as input, except along the given axis.
>>> x = torch.tensor([1, 2, 3]) >>> x.repeat_interleave(2) tensor([1, 1, 2, 2, 3, 3]) >>> y = torch.tensor([[1, 2], [3, 4]]) >>> torch.repeat_interleave(y, 2) tensor([1, 1, 2, 2, 3, 3, 4, 4]) >>> torch.repeat_interleave(y, 3, dim=1) tensor([[1, 1, 1, 2, 2, 2], [3, 3, 3, 4, 4, 4]]) >>> torch.repeat_interleave(y, torch.tensor([1, 2]), dim=0) tensor([[1, 2], [3, 4], [3, 4]])
torch.
repeat_interleave
(repeats) → Tensor文章来源:https://www.toymoban.com/news/detail-682154.html
If the repeats is tensor([n1, n2, n3, …]), then the output will be tensor([0, 0, …, 1, 1, …, 2, 2, …, …]) where 0 appears n1 times, 1 appears n2 times, 2 appears n3 times, etc.文章来源地址https://www.toymoban.com/news/detail-682154.html
到了这里,关于【Torch API】pytorch 中repeat_interleave函数详解的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!