MCPcopy Create free account
hub / github.com/ddbourgin/numpy-ml / random_binary_tensor

Function random_binary_tensor

numpy_ml/utils/testing.py:91–96  ·  view source on GitHub ↗

Create a random binary tensor of shape `shape`. `sparsity` is a value between 0 and 1 controlling the ratio of 0s to 1s in the output tensor.

(shape, sparsity=0.5)

Source from the content-addressed store, hash-verified

89
90
91def random_binary_tensor(shape, sparsity=0.5):
92 """
93 Create a random binary tensor of shape `shape`. `sparsity` is a value
94 between 0 and 1 controlling the ratio of 0s to 1s in the output tensor.
95 """
96 return (np.random.rand(*shape) >= (1 - sparsity)).astype(float)
97
98
99def random_paragraph(n_words, vocab=None):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected