samples : 1-D ndarray, shape (size,)
The generated random samples
if size is None:
size = 1
if isinstance(a, int):
a = th.arange(0, a)
if p is None:
After Change
if replace:
idx = th.floor(th.rand(n_samples)*a.size(0)).long()
else:
idx = th.randperm(len(a))[:n_samples]
else:
if abs(1.0-sum(p)) > 1e-3:
raise ValueError("p must sum to 1.0")
if not replace:
raise ValueError("replace must equal true if probabilities given")
idx_vec = th.cat([th.zeros(round(p[i]*1000))+i for i in range(len(p))])
idx = (th.floor(th.rand(n_samples)*999)).long()
idx = idx_vec[idx].long()
selection = a[idx]
if n_samples == 1:
selection = selection[0]
return selection
def save_transform(file, transform):