Thank you for your reply on my inquiry.
When I run the same code on my environment, it raises with the error below.

RuntimeErrorTraceback (most recent call last)
 in ()
----> 1 x.index_copy_(1, index, t)
RuntimeError: index_copy_(): Source/destination tensor must have same slice shapes. Destination slice shape: [5] at dimension 1 and source slice shape: [3] at dimension 0.
I am running this code in torch version 0.4.0.
What I notice is that if I run the same code on the torch version 0.3.1, then it runs as I expected, but it does not run properly once I use torch version 0.4.0. Do you know how to run this code on version 0.4.0?
Thank you!