Ask Question
13 January, 15:59

Write a python code that creates a numpy array of 10 randomly generated values between 0 and 100.

+4
Answers (1)
  1. 13 January, 16:09
    0
    import random #random to generate random integers.

    import numpy as np #numpy to create a numpy array.

    lis=[]#empty list.

    random. seed () #seed to generate every time differnt random integers.

    for i in range (10) : #looping 10 times.

    a=random. randint (0,101) #generating random numbers.

    lis. append (a) #inserting into the lis list.

    np_lis=np. array (lis) #converting lis to numpy array.

    print (np_lis) #print the numpy array.

    Explanation:

    The above-written code generates a numpy array of 10 randomly generated integers. I have first created an emmpty list lis. To generate random numbers we have import random library. random. seed is used so that every time distinct random number are generated. The for loop is run 10 times. In for loop random number generated is stored in the variable a then it is added to the list lis. Then after the loop finishes the lis list is converted to numpy array np_lis.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Write a python code that creates a numpy array of 10 randomly generated values between 0 and 100. ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers