Tuesday, June 08, 2021

Why do we use np.random.seed()


This is a simple function but to my surprise lot of ML engineers had asked me about the actual usage of this function and why do I use it when i am working on an algorithm which will be shared with other engineers. 


The simple answer is :

the function generates a random deterministic number. It generated the same random number each time for a specified seed  

"It's a random function with deterministic output for a specified seed. This helps to share the code and get the same output each time. "


Try this :


np.random.seed(1)

np.random.randint(low = 1, high = 10, size = 20)


The output will be, each time till seed is specified as "1" 

array([6, 9, 6, 1, 1, 2, 8, 7, 3, 5, 6, 3, 5, 3, 5, 8, 8, 2, 8, 1])






No comments:

Why do we use np.random.seed()

This is a simple function but to my surprise lot of ML engineers had asked me about the actual usage of this function and why do I use it wh...