Python 中級
Hugo Bowne-Anderson
Data Scientist at DataCamp






import numpy as np
np.random.rand() # Pseudo-random numbers
0.9535543896720104 # Mathematical formula
np.random.seed(123) # Starting from a seed
np.random.rand()
0.6964691855978616
np.random.rand()
0.28613933495037946
np.random.seed(123)
np.random.rand()
0.696469185597861 # 同樣的種子:得到相同的隨機數!
np.random.rand() # 確保「可重現性」
0.28613933495037946
game.py
import numpy as npnp.random.seed(123)coin = np.random.randint(0,2) # 隨機產生 0 或 1print(coin)
0
game.py
import numpy as np np.random.seed(123) coin = np.random.randint(0,2) # 隨機產生 0 或 1 print(coin)if coin == 0: print("heads")else: print("tails")
0
heads
Python 中級