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)
| 75 | |
| 76 | |
| 77 | def 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 | |
| 91 | def random_binary_tensor(shape, sparsity=0.5): |
no outgoing calls
no test coverage detected