Trasforming a tensor to different size

Found rather a better solution through this thread.