forked from whai362/PSENet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rand.py
37 lines (26 loc) · 814 Bytes
/
rand.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#coding=utf-8
'''
Created on 2016年9月27日
@author: dengdan
'''
import numpy as np
import time
import random
rng = np.random.RandomState(int(time.time()))
rand = np.random.rand
"""
Create an array of the given shape and populate it with random samples from a uniform distribution over [0, 1)
"""
def normal(shape, mu = 0, sigma_square = 1):
return rng.normal(mu, np.sqrt(sigma_square), shape)
def randint(low = 2 ** 30, high = None, shape = None):
"""
low: the higher bound except when high is not None.
high: when it is not none, low must be smaller than it
shape: if not provided, a scalar will be returned
"""
return rng.randint(low = low, high = high, size = shape)
def shuffle(lst):
random.shuffle(lst)
def sample(lst, n):
return random.sample(lst, n)