Working of numpy array to torch tensor conversion
I want to know how the conversion from a NumPy array to a tensor happens in PyTorch as well as Tensorflow. Does it create a copy of the entire array or there is some in-place mechanism?
Secondly, how to clear the memory that was used earlier by the NumPy array that was later converted into a tensor.


When device is CPU in PyTorch, PyTorch and Numpy uses the same internal representation of n-dimensional arrays in memory, so when converted from a Numpy array to a PyTorch tensor no copy operation is performed, only the way they are represented internally is changed. Refer here.

Python garbage collector uses reference counts for clearing unused memory similar to shared pointers in C++.


