Hi,
Try the following solution.
import numpy as np
import torch

p = 0.3

m1 = torch.Tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
m2 = torch.Tensor([[3, 4, 2], [5, 1, 2], [0, 4, 2]])

A = torch.Tensor(np.random.choice([0,1], size=[len(m1),len(m1[0])], p=[1-p, p]))

m3 = torch.mul(1-A,m1) + torch.mul(A,m2)

print(m3)

Thanks