MCPcopy
hub / github.com/ddbourgin/numpy-ml / random_tensor

Function random_tensor

numpy_ml/utils/testing.py:77–88  ·  view source on GitHub ↗

Create a random real-valued tensor of shape `shape`. If `standardize` is True, ensure each column has mean 0 and std 1.

(shape, standardize=False)

Source from the content-addressed store, hash-verified

75
76
77def random_tensor(shape, standardize=False):
78 """
79 Create a random real-valued tensor of shape `shape`. If `standardize` is
80 True, ensure each column has mean 0 and std 1.
81 """
82 offset = np.random.randint(-300, 300, shape)
83 X = np.random.rand(*shape) + offset
84
85 if standardize:
86 eps = np.finfo(float).eps
87 X = (X - X.mean(axis=0)) / (X.std(axis=0) + eps)
88 return X
89
90
91def random_binary_tensor(shape, sparsity=0.5):

Callers 15

test_squared_errorFunction · 0.90
test_VAE_lossFunction · 0.90
test_WGAN_GP_lossFunction · 0.90
test_NCELossFunction · 0.90
test_squared_error_gradFunction · 0.90
test_cross_entropy_gradFunction · 0.90
test_sigmoid_activationFunction · 0.90
test_elu_activationFunction · 0.90
test_sigmoid_gradFunction · 0.90
test_elu_gradFunction · 0.90
test_tanh_gradFunction · 0.90
test_relu_gradFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected