Random (npg.random)
The npg.random module contains all random-array factories and the
seed utility. Set the seed once at the top of your script for
reproducible results:
import numpygrad as npg
npg.random.manual_seed(0) # or npg.manual_seed(0) — same effect
Random arrays
Function |
Description |
|---|---|
|
Uniform samples in |
|
Standard normal samples |
|
Random integers in |
|
Uniform samples in |
|
Normal samples with given mean and std |
|
Random permutation of |
All factory functions accept requires_grad and dtype keyword
arguments:
w = npg.random.randn((4, 4), requires_grad=True)
i = npg.random.randperm(1000) # shuffle indices
Seeding
npg.random.manual_seed(seed) (also available as npg.manual_seed)
Set the NumPy random seed globally for reproducible weight initialisation, data shuffling, and dropout masks:
npg.random.manual_seed(42)
model = npg.nn.MLP(4, [32], 2) # weights initialised with seed 42