You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
17 KiB
17 KiB
<html>
<head>
</head>
9. Use NumPy to generate a random number between 0 and 1
10. Use NumPy to generate an array of 25 random numbers sampled from a standard normal distribution
13. Write code that reproduces the output shown below.
</html>
NumPy Exercises¶
Now that we've learned about NumPy let's test your knowledge. We'll start off with a few simple tasks and then you'll be asked some more complicated questions.
IMPORTANT NOTE! Make sure you don't run the cells directly above the example output shown,
otherwise you will end up writing over the example output!
otherwise you will end up writing over the example output!
1. Import NumPy as np¶
In [1]:
2. Create an array of 10 zeros¶
In [ ]:
# CODE HERE
In [2]:
# DON'T WRITE HERE
Out[2]:
3. Create an array of 10 ones¶
In [ ]:
In [3]:
# DON'T WRITE HERE
Out[3]:
4. Create an array of 10 fives¶
In [ ]:
In [4]:
# DON'T WRITE HERE
Out[4]:
5. Create an array of the integers from 10 to 50¶
In [ ]:
In [5]:
# DON'T WRITE HERE
Out[5]:
6. Create an array of all the even integers from 10 to 50¶
In [ ]:
In [6]:
# DON'T WRITE HERE
Out[6]:
7. Create a 3x3 matrix with values ranging from 0 to 8¶
In [ ]:
In [7]:
# DON'T WRITE HERE
Out[7]:
8. Create a 3x3 identity matrix¶
In [ ]:
In [8]:
# DON'T WRITE HERE
Out[8]:
9. Use NumPy to generate a random number between 0 and 1
NOTE: Your result's value should be different from the one shown below.
In [ ]:
In [9]:
# DON'T WRITE HERE
Out[9]:
10. Use NumPy to generate an array of 25 random numbers sampled from a standard normal distribution
NOTE: Your result's values should be different from the ones shown below.
In [ ]:
In [10]:
# DON'T WRITE HERE
Out[10]:
11. Create the following matrix:¶
In [ ]:
In [11]:
# DON'T WRITE HERE
Out[11]:
12. Create an array of 20 linearly spaced points between 0 and 1:¶
In [ ]:
In [12]:
# DON'T WRITE HERE
Out[12]:
Numpy Indexing and Selection¶
Now you will be given a starting matrix (be sure to run the cell below!), and be asked to replicate the resulting matrix outputs:
In [13]:
# RUN THIS CELL - THIS IS OUR STARTING MATRIX
mat = np.arange(1,26).reshape(5,5)
mat
Out[13]:
13. Write code that reproduces the output shown below.
Be careful not to run the cell immediately above the output, otherwise you won't be able to see the output any more.
In [ ]:
# CODE HERE
In [14]:
# DON'T WRITE HERE
Out[14]:
14. Write code that reproduces the output shown below.¶
In [ ]:
In [15]:
# DON'T WRITE HERE
Out[15]:
15. Write code that reproduces the output shown below.¶
In [ ]:
In [16]:
# DON'T WRITE HERE
Out[16]:
16. Write code that reproduces the output shown below.¶
In [ ]:
In [17]:
# DON'T WRITE HERE
Out[17]:
17. Write code that reproduces the output shown below.¶
In [ ]:
In [18]:
# DON'T WRITE HERE
Out[18]:
NumPy Operations¶
18. Get the sum of all the values in mat¶
In [ ]:
In [19]:
# DON'T WRITE HERE
Out[19]:
19. Get the standard deviation of the values in mat¶
In [ ]:
In [20]:
# DON'T WRITE HERE
Out[20]:
20. Get the sum of all the columns in mat¶
In [ ]:
In [21]:
# DON'T WRITE HERE
Out[21]:
Bonus Question¶
We worked a lot with random data with numpy, but is there a way we can insure that we always get the same random numbers? Click Here for a Hint
In [ ]: