I am able to do mentioned folding operation, but I face one small issue,
is there an easy way to solve this, if I have two tensors, something like,
a

tensor([[[[ 0.0000,  0.0000,  0.0000,  0.0000,  0.0000],
          [ 0.0000,  0.0000,  0.0000,  0.0000,  0.0000],
          [ 0.0000,  0.0000,  0.0000,  0.0000,  0.0000],
          [ 0.0000,  0.0000,  0.0000,  0.0000,  0.0000],
          [ 0.0000,  0.0000, -2.1455, -0.2417,  0.5321]]]])

and
b

tensor([[[[ 0.3462,  0.0000,  0.0000,  0.0000,  0.4700],
          [ 0.0000,  0.0000,  0.0000,  0.0000,  0.0000],
          [ 0.0000,  0.0000,  0.0000,  0.0000,  0.0000],
          [ 0.0000,  0.0000,  0.0000,  0.0000,  0.0000],
          [ 0.9115,  0.0000, -2.1455,  0.0000,  0.0000]]]])

now I want a combined tensor, that would have values if there is a non zero value at any of these two tensors, how do I do this, that is an OR operation on these two tensors. I cannot do
c = a or b

or
c = a | b

it give error, so I do, something like,
d = torch.tensor(a!=0).int()
e = torch.tensor(b!=0).int()
f = d + e
final = (a + b)/f
torch.where(final == final, final, zeros) # to remove nan values

and I get,
tensor([[[[ 0.3462,  0.0000,  0.0000,  0.0000,  0.4700],
          [ 0.0000,  0.0000,  0.0000,  0.0000,  0.0000],
          [ 0.0000,  0.0000,  0.0000,  0.0000,  0.0000],
          [ 0.0000,  0.0000,  0.0000,  0.0000,  0.0000],
          [ 0.9115,  0.0000, -2.1455, -0.2417,  0.5321]]]])

but is there an easier way to do this.