diff --git a/06 Lesson Numpy/Numpy Test.ipynb b/06 Lesson Numpy/Numpy Test.ipynb index c6898d9c..3c48c373 100644 --- a/06 Lesson Numpy/Numpy Test.ipynb +++ b/06 Lesson Numpy/Numpy Test.ipynb @@ -36,7 +36,7 @@ "id": "UelVcRZ-sAlh" }, "outputs": [], - "source": [] + "source": [import numpy as np] }, { "cell_type": "markdown", @@ -44,7 +44,7 @@ "colab_type": "text", "id": "bu2Riq11sAlm" }, - "source": [ + "source": [np.zeros(10) "#### Create an array of 10 zeros " ] }, @@ -77,7 +77,7 @@ "colab_type": "text", "id": "qOm0No5tsAlt" }, - "source": [ + "source": [np.ones(10) "#### Create an array of 10 ones" ] }, @@ -110,7 +110,7 @@ "colab_type": "text", "id": "PmtViTmxsAly" }, - "source": [ + "source": [ np.ones(10)*5 "#### Create an array of 10 fives" ] }, @@ -132,7 +132,7 @@ "colab_type": "text", "id": "o3GE-RG2sAl2" }, - "source": [ + "source": [np.arange(10,51) "#### Create an array of the integers from 10 to 50" ] }, @@ -167,7 +167,7 @@ "colab_type": "text", "id": "8W693KT0sAmA" }, - "source": [ + "source": [np.arange(10,51,2) "#### Create an array of all the even integers from 10 to 50" ] }, @@ -201,7 +201,8 @@ "colab_type": "text", "id": "O1WwNPlXsAmN" }, - "source": [ + "source": [a = np.array([[0,1,2],[3,4,5],[6,7,8]]) + np.transpose (a) "#### Create a 3x3 matrix with values ranging from 0 to 8" ] }, @@ -236,7 +237,8 @@ "colab_type": "text", "id": "p3ch73fusAma" }, - "source": [ + "source": [x = np.eye(3) + print(x) "#### Create a 3x3 identity matrix" ] }, @@ -271,7 +273,7 @@ "colab_type": "text", "id": "TwNdLZ8LsAml" }, - "source": [ + "source": [np.random.rand(1) "#### Use NumPy to generate a random number between 0 and 1" ] }, @@ -304,7 +306,7 @@ "colab_type": "text", "id": "mqAJJt1FsAmr" }, - "source": [ + "source": [np.random.randn(25) "#### Use NumPy to generate an array of 25 random numbers sampled from a standard normal distribution" ] }, @@ -341,7 +343,8 @@ "colab_type": "text", "id": "L1iG-GdnsAmw" }, - "source": [ + "source": [X_test = np.linespace(0,1,100) + X_test "#### Create the following matrix:" ] }, @@ -393,7 +396,7 @@ "colab_type": "text", "id": "KBZEt6tlsAm2" }, - "source": [ + "source": [np.linspace(0,1,20) "#### Create an array of 20 linearly spaced points between 0 and 1:" ] }, @@ -429,7 +432,8 @@ "colab_type": "text", "id": "AC2rcInYsAnB" }, - "source": [ + "source": [mat = np.arange(1,26).reashape(5,5) + mat "## Numpy Indexing and Selection\n", "\n", "Now you will be given a few matrices, and be asked to replicate the resulting matrix outputs:" @@ -471,7 +475,7 @@ "id": "_6ok-tAysAnG" }, "outputs": [], - "source": [ + "source": [ mat[2:,1:] "# WRITE CODE HERE THAT REPRODUCES THE OUTPUT OF THE CELL BELOW\n", "# BE CAREFUL NOT TO RUN THE CELL BELOW, OTHERWISE YOU WON'T\n", "# BE ABLE TO SEE THE OUTPUT ANY MORE" @@ -506,7 +510,7 @@ "id": "B4Mtdoj6sAnR" }, "outputs": [], - "source": [ + "source": [ "# WRITE CODE HERE THAT REPRODUCES THE OUTPUT OF THE CELL BELOW AS AN ARRAY\n", "# BE CAREFUL NOT TO RUN THE CELL BELOW, OTHERWISE YOU WON'T\n", "# BE ABLE TO SEE THE OUTPUT ANY MORE" @@ -528,7 +532,7 @@ "output_type": "execute_result" } ], - "source": [] + "source": [mat [3][4]] }, { "cell_type": "code", @@ -539,7 +543,7 @@ "id": "h8AJ_bd-sAna" }, "outputs": [], - "source": [ + "source": [ mat [0:3,1].reshape(3,1) "# WRITE CODE HERE THAT REPRODUCES THE OUTPUT OF THE CELL BELOW\n", "# BE CAREFUL NOT TO RUN THE CELL BELOW, OTHERWISE YOU WON'T\n", "# BE ABLE TO SEE THE OUTPUT ANY MORE" @@ -581,7 +585,7 @@ "id": "ngFWEzPPsAnp" }, "outputs": [], - "source": [ + "source": [ mat [4] "# WRITE CODE HERE THAT REPRODUCES THE OUTPUT OF THE CELL BELOW\n", "# BE CAREFUL NOT TO RUN THE CELL BELOW, OTHERWISE YOU WON'T\n", "# BE ABLE TO SEE THE OUTPUT ANY MORE" @@ -621,7 +625,7 @@ "id": "y0JlER1WsAnx" }, "outputs": [], - "source": [ + "source": [mat [3] "# WRITE CODE HERE THAT REPRODUCES THE OUTPUT OF THE CELL BELOW\n", "# BE CAREFUL NOT TO RUN THE CELL BELOW, OTHERWISE YOU WON'T\n", "# BE ABLE TO SEE THE OUTPUT ANY MORE" @@ -669,7 +673,7 @@ "colab_type": "text", "id": "jBIAJoezsAn3" }, - "source": [ + "source": [np.sum(mat) "#### Get the sum of all the values in mat" ] }, @@ -734,7 +738,7 @@ "colab_type": "text", "id": "UKEr75mxsAn_" }, - "source": [ + "source": [mat.sum(axis=0) "#### Get the sum of all the columns in mat" ] },