Skip to content

Commit 0bf6362

Browse files
committed
Add data util to mask data
1 parent 6d31004 commit 0bf6362

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import numpy as np
2+
3+
4+
def random_zero_array(arr, p, mask_token):
5+
"""
6+
Randomly zero out elements of an array with probability p
7+
"""
8+
mask = np.random.choice([0, 1], size=arr.shape, p=[p, 1 - p])
9+
return arr * mask + mask_token * (1 - mask)

0 commit comments

Comments
 (0)