# Tensor Copy Issue

**URL:** <https://discuss.pytorch.org/t/tensor-copy-issue/33557>\
**Category:** Uncategorized\
**Created:** [January 2, 2019, 3:44am UTC](https://discuss.pytorch.org/t/tensor-copy-issue/33557 "2019-01-02T03:44:43Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![woodsboy](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/woodsboy/32/17859_2.png) [@woodsboy](https://discuss.pytorch.org/u/woodsboy)\
**Post date:** [January 2, 2019, 3:44am UTC](https://discuss.pytorch.org/t/tensor-copy-issue/33557/1 "2019-01-02T03:44:43Z")

</div>

I have a question with Tensor copy, what I want is allocate the memory for a tensor outside a loop, and fill the data inner loop, but if I use c[batchId, :, :] = t3.t(), this seems a in plane operation(not differentiable), but if I use c[batchId, :, :].data = t3.().clone(), c is not change after the loop.

![image](https://discuss.pytorch.org/uploads/default/original/2X/6/69ee34ab7507015b4561fe2bde001c951f96b39a.png)

is there anyone could help me with the issue? thank you!

---

<div class="post-metadata">

**Author:** ![yunusemre](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/yunusemre/32/37214_2.png) [@yunusemre](https://discuss.pytorch.org/u/yunusemre)\
**Post date:** [January 2, 2019, 5:04pm UTC](https://discuss.pytorch.org/t/tensor-copy-issue/33557/2 "2019-01-02T17:04:10Z")

</div>

> [@\[resolved\] How does one create copy of tensors in PyTorch?](https://discuss.pytorch.org/t/resolved-how-does-one-create-copy-of-tensors-in-pytorch/6121):
>
> I was trying to create new copies (so that python was pointing at different objects and not just updating the same copy across multiple namespaces). I tried it by getting the actual numpy data from a tensor and using that to create a brand new tensor but that didn’t work. Why did it not work? How does one do this? \>\>\> y 3 3 3 3 3 3 [torch.FloatTensor of size 3x2] \>\>\> yv.data = torch.FloatTensor( y.numpy() ) \>\>\> yv Variable containing: 3 3 3 3 3 3 [torch.FloatTensor of size 3x2] \>\>…

I think you should check this.
