#!/usr/bin/env python # coding: utf-8 # # NumPy Exercises # # Numpy is desiged to handle large multidimensional arrays and enable efficient computations with them. In the back, it runs pre-compiled C code which is much faster than, say, a Python for loop. In this Numpy tutorial, we will covered the basics of Numpy, numpy arrays, element-wise operations, matrices operations and generating random matrices, indexing, slicing and broadcasting, which are useful concepts that will be reused in Pandas # # 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. # #### Import NumPy as np # In[1]: # #### Create an array of 10 zeros # In[2]: # #### Create an array of 10 ones # In[3]: # #### Create an array of 10 fives # In[4]: # #### Create an array of the integers from 10 to 50 # In[5]: # #### Create an array of all the even integers from 10 to 50 # In[6]: # #### Create a 3x3 matrix with values ranging from 0 to 8 # In[7]: # #### Create a 3x3 identity matrix # In[8]: # #### Use NumPy to generate a random number between 0 and 1 # In[15]: # #### Use NumPy to generate an array of 25 random numbers sampled from a standard normal distribution # In[33]: # #### Create the following matrix: # In[35]: # #### Create an array of 20 linearly spaced points between 0 and 1: # In[36]: # ## Numpy Indexing and Selection # # Now you will be given a few matrices, and be asked to replicate the resulting matrix outputs: # In[38]: mat = np.arange(1,26).reshape(5,5) mat # In[39]: # WRITE CODE HERE THAT REPRODUCES THE OUTPUT OF THE CELL BELOW # BE CAREFUL NOT TO RUN THE CELL BELOW, OTHERWISE YOU WON'T # BE ABLE TO SEE THE OUTPUT ANY MORE # In[40]: # In[29]: # WRITE CODE HERE THAT REPRODUCES THE OUTPUT OF THE CELL BELOW # BE CAREFUL NOT TO RUN THE CELL BELOW, OTHERWISE YOU WON'T # BE ABLE TO SEE THE OUTPUT ANY MORE # In[41]: # In[30]: # WRITE CODE HERE THAT REPRODUCES THE OUTPUT OF THE CELL BELOW # BE CAREFUL NOT TO RUN THE CELL BELOW, OTHERWISE YOU WON'T # BE ABLE TO SEE THE OUTPUT ANY MORE # In[42]: # In[31]: # WRITE CODE HERE THAT REPRODUCES THE OUTPUT OF THE CELL BELOW # BE CAREFUL NOT TO RUN THE CELL BELOW, OTHERWISE YOU WON'T # BE ABLE TO SEE THE OUTPUT ANY MORE # In[46]: # In[32]: # WRITE CODE HERE THAT REPRODUCES THE OUTPUT OF THE CELL BELOW # BE CAREFUL NOT TO RUN THE CELL BELOW, OTHERWISE YOU WON'T # BE ABLE TO SEE THE OUTPUT ANY MORE # In[49]: # ### Now do the following # #### Get the sum of all the values in mat # In[50]: # #### Get the standard deviation of the values in mat # In[51]: # #### Get the sum of all the columns in mat # In[53]: # # Great Job!