I am building neural networks in Pytorch, I see view
and view_as
used interchangeably in various implementation what is the difference between them?
Returns a new tensor with the same data as the self tensor but of a different shape . Otherwise, it will not be possible to view self tensor as shape without copying it (e.g., via contiguous() ).
Difference between view() and reshape(): view() cannot apply on 'non-contiguous' tensor /view. It returns a view. reshape() can apply on both 'contiguous' and 'non-contiguous' tensor/view.
The semantics of reshape() are that it may or may not share the storage and you don't know beforehand. Another difference is that reshape() can operate on both contiguous and non-contiguous tensor while view() can only operate on contiguous tensor. Also see here about the meaning of contiguous .
A view function, or view for short, is a Python function that takes a web request and returns a web response. This response can be the HTML contents of a web page, or a redirect, or a 404 error, or an XML document, or an image . . . or anything, really.
view
and view_as
are very similar with a slight difference. In view()
the shape of the desired output tensor is to be passed in as the parameter, whereas in view_as()
a tensor whose shape is to be mimicked is passed.
tensor.view_as(other)
is equivalent to tensor.view(other.size())
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With