You could sample a binary mask using the drop probability p and fill the tensor with your desired value:
x = torch.ones(10, 20)

p = 0.5
mask = torch.distributions.Bernoulli(probs=(1-p)).sample(x.size())
x[~mask.bool()] = x.mean()

Note that dropout scales also the activation to make sure the expected activation ranges are equal during training and validation via:
# manual dropout
out = x * mask * 1/(1-p)

So you would have to take care of this scaling for your approach.