Hi, It’s a strange operation dude.
You can create tensors directly on gpu with
torch.zeros(shape,device='cuda:id')
If you don’t want to pad you can just create a mask of boolean values and do something like
y_matrix[mask] = 1.
That would be executed directly on gpu.
Hope it helps or someone find a better way
edit:
Another alternative would be creating a tensor with method torch.cudatensor (or something likle that) containing all the elements and then reshaping.