Numpy.ndarray have flat()
, I know x.view(-1)
can do so same result for the torch.Tensor, but I hope there is a good function can replace this unclear expression.
1 Like
I noticed that flat is not I want while it is an iterator actually, and flatten
return copy, so the idea function is ravel
. However Tensor still does not have any function called this.
>>> a = torch.rand(2,3)
>>> a
0.6496 0.8958 0.3040
0.2913 0.1609 0.6008
[torch.FloatTensor of size 2x3]
>>> a_flat = a.view(a.numel())
>>> a_flat
0.6496
0.8958
0.3040
0.2913
0.1609
0.6008
[torch.FloatTensor of size 6]
5 Likes
You could also just write, using the default size:
>>>a_flat = a.view(-1)