Torch - repeat tensor like numpy repeat -
i trying repeat tensor in torch in 2 ways. example repeating tensor {1,2,3,4}
3 times both ways yield;
{1,2,3,4,1,2,3,4,1,2,3,4} {1,1,1,2,2,2,3,3,3,4,4,4}
there built in torch:repeattensor function generate first of 2 (like numpy.tile()
) can't find 1 latter (like numpy.repeat()
). i'm sure call sort on first give second think might computationally expensive larger arrays?
thanks.
a = torch.tensor{1,2,3,4}
to {1,2,3,4,1,2,3,4,1,2,3,4}
repeat tensor thrice in 1st dimension:
a:repeattensor(3)
to {1,1,1,2,2,2,3,3,3,4,4,4}
add dimension tensor , repeat thrice in 2nd dimension 4 x 3
tensor, can flatten.
b = a:reshape(4,1):repeattensor(1,3) b:view(b:nelement())
Comments
Post a Comment