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

猜你喜欢

转载自blog.csdn.net/zz2230633069/article/details/83505793