Create a random array _1

  • Syntax
numpy.random.random(size=None)
  • numpy.random.randint()
The method has three parameters low, high, size three parameters. The default is high None, if only low, that is the range [0, low). If there is high, the range is [low, high).
  • Code

1  # import module 
2  Import numpy AS NP 
 . 3  DEF randomTest ():
 . 4      # used to create a one-dimensional random arrays 
. 5      A = np.random.random (size =. 5 )
 . 6      Print (A)
 . 7      Print (type (A))
 . 8      Print ( " *********************************************** * " )
 . 9  
10      # create a two-dimensional array 
. 11      B = np.random.random (size = (3,4- ))
 12 is      Print (B)
 13 is      Print ( "**************************** " )
 14  
15      # Create a three-dimensional array 
16      C = np.random.random (size = (2,3,4 ))
 . 17      Print (C)
 18 is      Print ( " ********************************************************* ******************************** ' )
 . 19  
20 is  # random integer 
21 is  DEF randomintTest ():
 22 is      # generated 0- random integer (one-dimensional) between. 5 
23 is      a = np.random.randint (. 6, size = 10 )
 24      Print (a)
 25      Print (type (a))
 26 is      Print (" **************************** " )
 27  
28      # to generate a random integer between 5-10 
29      B = np.random.randint (5,11, size = (4,3- ))
 30      Print (B)
 31 is      Print ( " ******* ***************************************** " )
 32  
33 is      # generates 5-10 a random number (D) between 
34 is      C = np.random.randint (5,11, size = (2,4,3 ))
 35      Print (C)
 36      Print ( " ********** ************************************** " )
 37 [  
38 is # Call 
39  randomTest ()
 40 randomintTest ()
 1 [0.58481035 0.89981199 0.4430777  0.79111114 0.80530942]
 2 <class 'numpy.ndarray'>
 3 ************************************************
 4 [[0.62548615 0.30478776 0.80835854 0.64659382]  
 5  [0.01354597 0.55416311 0.28586102 0.13735663]  
 6  [0.51881331 0.21160145 0.72725684 0.99663842]] 
 7 ************************************************
 8 [[[0.08170694 0.9253817  0.65025442 0.04592365] 
 9   [0.36387681 0.65987097 0.10837108 0.15505963]
10   [0.77084731 0.00175051 0.44813178 0.82772988]]
11 
12  [[0.73729773 0.65277105 0.68823734 0.0330837 ]
13   [0.32585801 0.72776357 0.90520657 0.69459254]
14   [0.30655539 0.72554569 0.73852885 0.80749657]]]
15 ************************************************
16 [3 4 4 1 4 2 4 5 4 0]
17 <class 'numpy.ndarray'>
18 ************************************************
19 [[ 5  6  9]
20  [10 10  5]
21  [ 9  6  6]
22  [ 9  8  6]]
23 ************************************************
24 [[[ 7  6  7]
25   [ 9  6 10]
26   [ 8  7 10]
27   [10  9  7]]
28 
29  [[ 7  6  5]
30   [ 9 10  8]
31   [ 6  7  7]
32   [ 9  6  8]]]
33 ************************************************

 

Guess you like

Origin www.cnblogs.com/monsterhy123/p/12584554.html