Based on the error message the indexed tensor has a shape of [31], while the value tensor has a shape of [32]. This code snippet illustrates the issue:
x = torch.randn(32)
idx = torch.ones(32).bool()
x[idx] = torch.randn(32) # works

idx[0] = False
x[idx] = torch.randn(32) # fails
# > RuntimeError: shape mismatch: value tensor of shape [32] cannot be broadcast to indexing result of shape [31]

so you won’t be able to assign 32 values to the x[idx] which is indexing 31 values only.