linyu
(linyu)
January 5, 2019, 5:30am
1
I have an origin tensor [0,1;2,3], how can I efficiently get [0,0,1,1;0,0,1,1;2,2,3,3;2,2,3,3]?
yunusemre
(Yunusemre)
January 5, 2019, 7:24am
2
I think this post should help you:
If I have a tensor like:
z = torch.FloatTensor([[1,2,3],[4,5,6]])
1 2 3
4 5 6
How might I turn it into a tensor like:
1 2 3
1 2 3
1 2 3
1 2 3
4 5 6
4 5 6
4 5 6
4 5 6
I imagine that torch.repeat() is somehow in play here.
The only solution I have come up with is to do:
z.repeat(1,4).view(-1, 3)
Is there one operation that collapses these two commands into one?
Moreover, if I have columnwise data I want to repeat, how can I do this without transposing the data back and forth? For example,…
As mentioned here How to tile a tensor? - #2 by richard , we can build wit .repeat()
and .view()
. For your solution: a.view(-1, 1).repeat(1,2).view(2,4).repeat(1,2).view(4,4)