How to transfer an existing tensor to another device based on other tensor

For example

tensor_a is currently in cpu
I wanna transfer tensor_a to cpu or gpu based on 
tensor_b's residential state.
tensor_a = tensor_a.cuda(b.get_device()) if b.is_cuda else tensor_a
3 Likes

good to know that, thanks!