numpy random array

1.numpy.random.rand()

  Create a random array of the specified size in the range [0, 1)

Import numpy NP AS 

# array to create two rows and two columns in the range [0,1) 
arr = np.random.rand (2,2)

  or

Import numpy NP AS 

# Create a one-dimensional array, the number of elements is 10, the range [0,1) 
of arr1 = np.random.rand (10)

2.numpy.random.randn()

  Create an array of the specified size, ranging from standard normal distribution

# Create two rows and three columns, the range of the standard normal distribution array 
arr2 = np.random.randn (2,3)

3.numpy.random.randint()

  Creating the specified size array, the array take on the value of the random [low, high) between. is empty then take high [0, low). You need to use size attribute specifies the size of the array.

arr3 = np.random.randint(1,20,size=(2,2,3))

4.numpy.random.choice()

  numpy.random.choice(a, size=None, replace=True, p=None)

  a: the specified one-dimensional array or an integer. If is an integer, the method is equivalent to np.arange (a)

  size: size of the array

  replace: the element array is generated can be repeated. The default is True, which can be repeated

  The probability of occurrence of each element one-dimensional array: p

5.numpy.random.shuffle()

  The elements in the array upset.

arr4 = np.random.shuffle(arr1)

6.numpy.random.seed()

  Generate a random number seed

# Generate a random number seed seed1, their parameters can be arbitrarily set 
np.random.seed (seed1)

  Its role is to seed the random array associated with the random number generated at once so that, if the random number seed associated with the random array is the same, and an array of the same size, the random array is the same. Related approach is to add before np.random.seed (seed1).

  It is easily understood: the premise of the same random number seed association, the first array which generated random element size (of course, within the specified size range), and thereafter generates a random array of first generation the position of the overlapping portion of the array, which elements are the same, if extended, press generates a random principle. Its essence is to eliminate certain randomness in the random premise.

Guess you like

Origin www.cnblogs.com/jason--/p/11567316.html