1. 程式人生 > >pytorch 中的view和permute的用法

pytorch 中的view和permute的用法

view相當於numpy中resize()的功能,但是用法可能不太一樣.可以參考:https://blog.csdn.net/york1996/article/details/81949843

view只能用在contiguous的variable上。如果在view之前用了transpose,permute等,需要用contiguous()來返回一個contiguous copy 可參考:https://blog.csdn.net/appleml/article/details/80143212?utm_source=blogxgwz0

但是在pytorch最新版本0.4版本中,增加了torch.reshape(),這個與numpy.reshape 的功能類似。它大致相當於tensor.contiguous().view()

permute是維度換位,是更靈活的transpose,可以靈活的對原資料的維度進行調換,而資料本身不變(transpose也是)。

可以參考:https://blog.csdn.net/york1996/article/details/81876886

pytorch中的cat、stack、tranpose、permute、unsqeeze