How to replace every row that are filled with zero with a certain value from a Pytorch tensor?
I have a Pytorch tensor of the size bsize x 50 x 50 where some of the rows are completely filled with zeros:
         [[0, 2, 0,  ..., 0, 0, 0],
         [2, 0, 2,  ..., 0, 0, 0],
         [0, 2, 0,  ..., 0, 0, 0],
         ...,
         [0, 0, 0,  ..., 0, 0, 0],
         [0, 0, 0,  ..., 0, 0, 0],
         [0, 0, 0,  ..., 0, 0, 0]],

        [[0, 2, 0,  ..., 0, 0, 0],
         [2, 0, 2,  ..., 0, 0, 0],
         [0, 2, 0,  ..., 0, 0, 0],

I want to  replace the rows filled with zeros with a negative value -100 throughout in the tensor.
Expected tensor -
         [[0, 2, 0,  ..., 0, 0, 0],
         [2, 0, 2,  ..., 0, 0, 0],
         [0, 2, 0,  ..., 0, 0, 0],
         ...,
         [-100, -100, -100,  ..., -100,-100, -100],
         [-100, -100, -100,  ..., -100,-100, -100],
         [-100, -100, -100,  ..., -100,-100, -100]],

        [[0, 2, 0,  ..., 0, 0, 0],
         [2, 0, 2,  ..., 0, 0, 0],
         [0, 2, 0,  ..., 0, 0, 0],

Whats the best way to do this avoiding a loop over the row shape ?

Assuming x is your tensor with BxRxC (batch, rows, and columns), you can do something like this:
x[(x == 0).all(dim=-1)] = -100

Basically:

x == 0 returns a boolean tensor (shape BxRxC) with True where it is equal to zero;
then, .all(dim=-1) returns another boolean tensor, now with shape BxR because we chose to do all in the last dimension (-1), with True where all the columns are True;
finally, we use this boolean tensor to index the original tensor and the -100 is assigned to the True positions.

