NumPy exercises

In [ ]:
#import the Numpy package
import numpy as np
In [2]:
#Set the random seed
np.random.seed(859)
In [4]:
#Create a random array of 100 values between 0 and 1
arr_1 = 

#Display the resulting array
arr_1
Out[4]:
array([0.15700854, 0.41080809, 0.98507234, 0.3801485 , 0.33949913,
       0.21982355, 0.2931561 , 0.41817129, 0.14498206, 0.02424045,
       0.00920897, 0.33717002, 0.05197823, 0.9150345 , 0.92046476,
       0.42083261, 0.97857695, 0.24257692, 0.29083097, 0.48834308,
       0.57374361, 0.90344002, 0.2951836 , 0.0562096 , 0.24817813,
       0.93343119, 0.02332197, 0.73828503, 0.23900878, 0.60235213,
       0.1819568 , 0.35610882, 0.72831219, 0.21508016, 0.80068247,
       0.17679207, 0.40265315, 0.12841897, 0.33216432, 0.01726349,
       0.08326946, 0.28808968, 0.41045931, 0.11091862, 0.75661554,
       0.90401755, 0.81256798, 0.57781609, 0.60326138, 0.70112676,
       0.0707155 , 0.94056194, 0.46971289, 0.84167641, 0.44773881,
       0.41299915, 0.93992695, 0.16517926, 0.28406607, 0.85071314,
       0.30394712, 0.25039873, 0.88321642, 0.58485085, 0.73664309,
       0.21862636, 0.47401317, 0.42029544, 0.58658383, 0.45716522,
       0.69006102, 0.8402728 , 0.43641648, 0.59148953, 0.49324441,
       0.95447362, 0.26670595, 0.46401931, 0.74906676, 0.5122483 ,
       0.50116087, 0.03902179, 0.53125825, 0.80469   , 0.66603986,
       0.19955797, 0.6750979 , 0.22957888, 0.23197042, 0.47677797,
       0.47819954, 0.49556007, 0.37779617, 0.32043922, 0.35460052,
       0.25491687, 0.50425818, 0.23652773, 0.75551306, 0.64988585])
In [5]:
#Report the shape of the resulting array
Out[5]:
(100,)
In [6]:
#Report the data type of the resulting array
Out[6]:
dtype('float64')
In [8]:
#Remote the mean value of all values in your array
Out[8]:
0.4634853558185105
In [7]:
#Multiply each value in your array to get values between 0 and 100, saving the results as "arr_2"
arr_2 = 
Out[7]:
array([1.57008535, 4.10808091, 9.85072337, 3.80148502, 3.39499133,
       2.19823548, 2.93156103, 4.1817129 , 1.44982064, 0.24240449,
       0.09208974, 3.37170019, 0.51978225, 9.15034496, 9.20464763,
       4.20832613, 9.78576952, 2.42576919, 2.90830965, 4.88343076,
       5.73743614, 9.03440016, 2.95183598, 0.56209596, 2.48178133,
       9.3343119 , 0.23321973, 7.38285029, 2.39008781, 6.02352134,
       1.81956803, 3.56108823, 7.28312186, 2.15080163, 8.00682471,
       1.76792072, 4.0265315 , 1.28418966, 3.32164324, 0.17263487,
       0.83269465, 2.8808968 , 4.10459312, 1.10918621, 7.56615539,
       9.0401755 , 8.12567983, 5.77816092, 6.03261376, 7.01126764,
       0.70715499, 9.40561936, 4.69712894, 8.41676408, 4.47738806,
       4.12999145, 9.39926951, 1.65179263, 2.84066066, 8.50713139,
       3.03947124, 2.50398729, 8.83216419, 5.8485085 , 7.36643089,
       2.18626358, 4.74013166, 4.20295439, 5.86583825, 4.57165216,
       6.90061018, 8.40272805, 4.36416479, 5.91489531, 4.93244413,
       9.54473623, 2.66705951, 4.64019305, 7.49066765, 5.12248296,
       5.0116087 , 0.3902179 , 5.3125825 , 8.04689999, 6.66039864,
       1.99557968, 6.75097905, 2.29578879, 2.31970419, 4.7677797 ,
       4.78199538, 4.95560067, 3.77796175, 3.2043922 , 3.54600521,
       2.54916868, 5.04258184, 2.36527729, 7.55513057, 6.49885854])
In [ ]:
#Reshape the array above to be 25 rows and 4 columns, saving the result as "arr_3"
arr_3 = 
In [15]:
#Show the 3rd row of this array
Out[15]:
array([1.44982064, 0.24240449, 0.09208974, 3.37170019])
In [18]:
#Show the values in the 2nd column of this array
Out[18]:
array([4.10808091, 2.19823548, 0.24240449, 9.15034496, 2.42576919,
       9.03440016, 9.3343119 , 6.02352134, 2.15080163, 1.28418966,
       2.8808968 , 9.0401755 , 7.01126764, 8.41676408, 1.65179263,
       2.50398729, 2.18626358, 4.57165216, 5.91489531, 4.64019305,
       0.3902179 , 1.99557968, 4.7677797 , 3.2043922 , 2.36527729])
In [17]:
#Show the mean of the values in the 2nd column
Out[17]:
4.2997277811874435