Ask Question
24 April, 06:35

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

+5
Answers (1)
  1. 24 April, 10:15
    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?
Get 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 there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers