Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save CoderNamedHendrick/67bdfb708929c6737dfae4946820ee2f to your computer and use it in GitHub Desktop.
Save CoderNamedHendrick/67bdfb708929c6737dfae4946820ee2f to your computer and use it in GitHub Desktop.
Created on Skills Network Labs
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<a href=\"https://cognitiveclass.ai/\">\n",
" <img src=\"https://s3-api.us-geo.objectstorage.softlayer.net/cf-courses-data/CognitiveClass/PY0101EN/Ad/CCLog.png\" width=\"200\" align=\"center\">\n",
"</a>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<h1>1D <code>Numpy</code> in Python</h1>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<p><strong>Welcome!</strong> This notebook will teach you about using <code>Numpy</code> in the Python Programming Language. By the end of this lab, you'll know what <code>Numpy</code> is and the <code>Numpy</code> operations.</p>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<div class=\"alert alert-block alert-info\" style=\"margin-top: 20px\">\n",
" <a href=\"https://cocl.us/NotebooksPython101\">\n",
" <img src=\"https://s3-api.us-geo.objectstorage.softlayer.net/cf-courses-data/CognitiveClass/PY0101EN/Ad/TopAd.png\" width=\"750\" align=\"center\">\n",
" </a>\n",
"</div>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<h2>Table of Contents</h2>\n",
"<div class=\"alert alert-block alert-info\" style=\"margin-top: 20px\">\n",
" <ul>\n",
" <li><a href=\"pre\">Preparation</a></li>\n",
" <li>\n",
" <a href=\"numpy\">What is Numpy?</a>\n",
" <ul>\n",
" <li><a href=\"type\">Type</a></li>\n",
" <li><a href=\"val\">Assign Value</a></li>\n",
" <li><a href=\"slice\">Slicing</a></li>\n",
" <li><a href=\"list\">Assign Value with List</a></li>\n",
" <li><a href=\"other\">Other Attributes</a></li>\n",
" </ul>\n",
" </li>\n",
" <li>\n",
" <a href=\"op\">Numpy Array Operations</a>\n",
" <ul>\n",
" <li><a href=\"add\">Array Addition</a></li>\n",
" <li><a href=\"multi\">Array Multiplication</a></li>\n",
" <li><a href=\"prod\">Product of Two Numpy Arrays</a></li>\n",
" <li><a href=\"dot\">Dot Product</a></li>\n",
" <li><a href=\"cons\">Adding Constant to a Numpy Array</a></li>\n",
" </ul>\n",
" </li>\n",
" <li><a href=\"math\">Mathematical Functions</a></li>\n",
" <li><a href=\"lin\">Linspace</a></li>\n",
" </ul>\n",
" <p>\n",
" Estimated time needed: <strong>30 min</strong>\n",
" </p>\n",
"</div>\n",
"\n",
"<hr>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<h2 id=\"pre\">Preparation</h2>"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"# Import the libraries\n",
"\n",
"import time \n",
"import sys\n",
"import numpy as np \n",
"\n",
"import matplotlib.pyplot as plt\n",
"%matplotlib inline "
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [],
"source": [
"# Plotting functions\n",
"\n",
"def Plotvec1(u, z, v):\n",
" \n",
" ax = plt.axes()\n",
" ax.arrow(0, 0, *u, head_width=0.05, color='r', head_length=0.1)\n",
" plt.text(*(u + 0.1), 'u')\n",
" \n",
" ax.arrow(0, 0, *v, head_width=0.05, color='b', head_length=0.1)\n",
" plt.text(*(v + 0.1), 'v')\n",
" ax.arrow(0, 0, *z, head_width=0.05, head_length=0.1)\n",
" plt.text(*(z + 0.1), 'z')\n",
" plt.ylim(-2, 2)\n",
" plt.xlim(-2, 2)\n",
"\n",
"def Plotvec2(a,b):\n",
" ax = plt.axes()\n",
" ax.arrow(0, 0, *a, head_width=0.05, color ='r', head_length=0.1)\n",
" plt.text(*(a + 0.1), 'a')\n",
" ax.arrow(0, 0, *b, head_width=0.05, color ='b', head_length=0.1)\n",
" plt.text(*(b + 0.1), 'b')\n",
" plt.ylim(-2, 2)\n",
" plt.xlim(-2, 2)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Create a Python List as follows:"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [],
"source": [
"# Create a python list\n",
"\n",
"a = [\"0\", 1, \"two\", \"3\", 4]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can access the data via an index:"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<img src=\"https://s3-api.us-geo.objectstorage.softlayer.net/cf-courses-data/CognitiveClass/PY0101EN/Chapter%205/Images/NumOneList.png\" width=\"660\" />"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can access each element using a square bracket as follows: "
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"a[0]: 0\n",
"a[1]: 1\n",
"a[2]: two\n",
"a[3]: 3\n",
"a[4]: 4\n"
]
}
],
"source": [
"# Print each element\n",
"\n",
"print(\"a[0]:\", a[0])\n",
"print(\"a[1]:\", a[1])\n",
"print(\"a[2]:\", a[2])\n",
"print(\"a[3]:\", a[3])\n",
"print(\"a[4]:\", a[4])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<hr>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<h2 id=\"numpy\">What is Numpy?</h2>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"A numpy array is similar to a list. It's usually fixed in size and each element is of the same type. We can cast a list to a numpy array by first importing numpy: "
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [],
"source": [
"# import numpy library\n",
"\n",
"import numpy as np "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
" We then cast the list as follows:"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [
{
"data": {
"text/plain": [
"array([0, 1, 2, 3, 4])"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Create a numpy array\n",
"\n",
"a = np.array([0, 1, 2, 3, 4])\n",
"a"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Each element is of the same type, in this case integers: "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<img src=\"https://s3-api.us-geo.objectstorage.softlayer.net/cf-courses-data/CognitiveClass/PY0101EN/Chapter%205/Images/NumOneNp.png\" width=\"500\" />"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
" As with lists, we can access each element via a square bracket:"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"a[0]: 0\n",
"a[1]: 1\n",
"a[2]: 2\n",
"a[3]: 3\n",
"a[4]: 4\n"
]
}
],
"source": [
"# Print each element\n",
"\n",
"print(\"a[0]:\", a[0])\n",
"print(\"a[1]:\", a[1])\n",
"print(\"a[2]:\", a[2])\n",
"print(\"a[3]:\", a[3])\n",
"print(\"a[4]:\", a[4])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<h3 id=\"type\">Type</h3>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"If we check the type of the array we get <b>numpy.ndarray</b>:"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [
{
"data": {
"text/plain": [
"numpy.ndarray"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Check the type of the array\n",
"\n",
"type(a)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"As numpy arrays contain data of the same type, we can use the attribute \"dtype\" to obtain the Data-type of the array’s elements. In this case a 64-bit integer: \n"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [
{
"data": {
"text/plain": [
"dtype('int64')"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Check the type of the values stored in numpy array\n",
"\n",
"a.dtype"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can create a numpy array with real numbers:"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [],
"source": [
"# Create a numpy array\n",
"\n",
"b = np.array([3.1, 11.02, 6.2, 213.2, 5.2])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"When we check the type of the array we get <b>numpy.ndarray</b>:"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [
{
"data": {
"text/plain": [
"numpy.ndarray"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Check the type of array\n",
"\n",
"type(b)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"If we examine the attribute <code>dtype</code> we see float 64, as the elements are not integers: "
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [
{
"data": {
"text/plain": [
"dtype('float64')"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Check the value type\n",
"\n",
"b.dtype"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<h3 id=\"val\">Assign value</h3>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can change the value of the array, consider the array <code>c</code>:"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [
{
"data": {
"text/plain": [
"array([20, 1, 2, 3, 4])"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Create numpy array\n",
"\n",
"c = np.array([20, 1, 2, 3, 4])\n",
"c"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can change the first element of the array to 100 as follows:"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [
{
"data": {
"text/plain": [
"array([100, 1, 2, 3, 4])"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Assign the first element to 100\n",
"\n",
"c[0] = 100\n",
"c"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can change the 5th element of the array to 0 as follows:"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [
{
"data": {
"text/plain": [
"array([100, 1, 2, 3, 0])"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Assign the 5th element to 0\n",
"\n",
"c[4] = 0\n",
"c"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<h3 id=\"slice\">Slicing</h3>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Like lists, we can slice the numpy array, and we can select the elements from 1 to 3 and assign it to a new numpy array <code>d</code> as follows:"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [
{
"data": {
"text/plain": [
"array([1, 2, 3])"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Slicing the numpy array\n",
"\n",
"d = c[1:4]\n",
"d"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can assign the corresponding indexes to new values as follows: "
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [
{
"data": {
"text/plain": [
"array([100, 1, 2, 300, 400])"
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Set the fourth element and fifth element to 300 and 400\n",
"\n",
"c[3:5] = 300, 400\n",
"c"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<h3 id=\"list\">Assign Value with List</h3>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Similarly, we can use a list to select a specific index.\n",
"The list ' select ' contains several values:\n"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [],
"source": [
"# Create the index list\n",
"\n",
"select = [0, 2, 3]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can use the list as an argument in the brackets. The output is the elements corresponding to the particular index:"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [
{
"data": {
"text/plain": [
"array([100, 2, 300])"
]
},
"execution_count": 20,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Use List to select elements\n",
"\n",
"d = c[select]\n",
"d"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can assign the specified elements to a new value. For example, we can assign the values to 100 000 as follows:"
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [
{
"data": {
"text/plain": [
"array([100000, 1, 100000, 100000, 400])"
]
},
"execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Assign the specified elements to new value\n",
"\n",
"c[select] = 100000\n",
"c"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<h3 id=\"other\">Other Attributes</h3>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Let's review some basic array attributes using the array <code>a</code>:"
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [
{
"data": {
"text/plain": [
"array([0, 1, 2, 3, 4])"
]
},
"execution_count": 22,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Create a numpy array\n",
"\n",
"a = np.array([0, 1, 2, 3, 4])\n",
"a"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The attribute <code>size</code> is the number of elements in the array:"
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [
{
"data": {
"text/plain": [
"5"
]
},
"execution_count": 23,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Get the size of numpy array\n",
"\n",
"a.size"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The next two attributes will make more sense when we get to higher dimensions but let's review them. The attribute <code>ndim</code> represents the number of array dimensions or the rank of the array, in this case, one:"
]
},
{
"cell_type": "code",
"execution_count": 24,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [
{
"data": {
"text/plain": [
"1"
]
},
"execution_count": 24,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Get the number of dimensions of numpy array\n",
"\n",
"a.ndim"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The attribute <code>shape</code> is a tuple of integers indicating the size of the array in each dimension:"
]
},
{
"cell_type": "code",
"execution_count": 25,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [
{
"data": {
"text/plain": [
"(5,)"
]
},
"execution_count": 25,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Get the shape/size of numpy array\n",
"\n",
"a.shape"
]
},
{
"cell_type": "code",
"execution_count": 26,
"metadata": {},
"outputs": [],
"source": [
"# Create a numpy array\n",
"\n",
"a = np.array([1, -1, 1, -1])"
]
},
{
"cell_type": "code",
"execution_count": 27,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [
{
"data": {
"text/plain": [
"0.0"
]
},
"execution_count": 27,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Get the mean of numpy array\n",
"\n",
"mean = a.mean()\n",
"mean"
]
},
{
"cell_type": "code",
"execution_count": 28,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [
{
"data": {
"text/plain": [
"1.0"
]
},
"execution_count": 28,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Get the standard deviation of numpy array\n",
"\n",
"standard_deviation=a.std()\n",
"standard_deviation"
]
},
{
"cell_type": "code",
"execution_count": 29,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [
{
"data": {
"text/plain": [
"array([-1, 2, 3, 4, 5])"
]
},
"execution_count": 29,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Create a numpy array\n",
"\n",
"b = np.array([-1, 2, 3, 4, 5])\n",
"b"
]
},
{
"cell_type": "code",
"execution_count": 30,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [
{
"data": {
"text/plain": [
"5"
]
},
"execution_count": 30,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Get the biggest value in the numpy array\n",
"\n",
"max_b = b.max()\n",
"max_b"
]
},
{
"cell_type": "code",
"execution_count": 31,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [
{
"data": {
"text/plain": [
"-1"
]
},
"execution_count": 31,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Get the smallest value in the numpy array\n",
"\n",
"min_b = b.min()\n",
"min_b"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<hr>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<h2 id=\"op\">Numpy Array Operations</h2>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<h3 id=\"add\">Array Addition</h3>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Consider the numpy array <code>u</code>:"
]
},
{
"cell_type": "code",
"execution_count": 32,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [
{
"data": {
"text/plain": [
"array([1, 0])"
]
},
"execution_count": 32,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"u = np.array([1, 0])\n",
"u"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Consider the numpy array <code>v</code>:"
]
},
{
"cell_type": "code",
"execution_count": 33,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [
{
"data": {
"text/plain": [
"array([0, 1])"
]
},
"execution_count": 33,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"v = np.array([0, 1])\n",
"v"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can add the two arrays and assign it to z:"
]
},
{
"cell_type": "code",
"execution_count": 34,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [
{
"data": {
"text/plain": [
"array([1, 1])"
]
},
"execution_count": 34,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Numpy Array Addition\n",
"\n",
"z = u + v\n",
"z"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
" The operation is equivalent to vector addition:"
]
},
{
"cell_type": "code",
"execution_count": 35,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAYQAAAD8CAYAAAB3u9PLAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAAYDklEQVR4nO3deZBdZbnv8e/TGRhCkCEJZCAQi3gheD0RW4ajUkTRCzlq9BRo1FLLKUI5FrcsuHIuUrcKC714LClEjCKDVyYZIySMCgHLYDqRQEgQGkxM6EBCQkI4Ycjw3D96mdMn7E53Z6/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xTT2bWd7KPXx7OG7oxP1Y9m6bL/jn8oMnNuRFwWEaMys9Ee0lb1WHZLo4xnRAyjPQx+k5m31GjS4/FsmENGMYAegxERIyJi5D+WaT9h3ohPbW2E8ZwDfL5Y/jzwpplNhePZnfGZA3yuuKLjBGDTPw6B9ZEua4yIQyMiiuXjaP//fn0f1thdVY9ltzTCeBb9XwEsz8x/76RZz8ezyjPlu5wRb6X9eNejxevy4v1xwNxdzpw/RfuVFedVUOfHaU/e14EXgLt3rZP2Kz6WFK8nGrXOBhnPg4H7gaeLnwc10njWGh/gTODMYjlo/wKoZ4DH2c2VZxXW+PVi3JbQfsHGP/d1jUUd1wFrgK3F7+aXGm0su1ln5eMJvJf2wz+PdfibOb3e8fTRFZIkoIEOGUmSqmUgSJIAA0GSVDAQJEmAgSBJKhgIkiTAQJAkFf4/c5+2+Q7CWMsAAAAASUVORK5CYII=\n",
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"# Plot numpy arrays\n",
"\n",
"Plotvec1(u, z, v)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<h3 id=\"multi\">Array Multiplication</h3>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Consider the vector numpy array <code>y</code>:"
]
},
{
"cell_type": "code",
"execution_count": 36,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [
{
"data": {
"text/plain": [
"array([1, 2])"
]
},
"execution_count": 36,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Create a numpy array\n",
"\n",
"y = np.array([1, 2])\n",
"y"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can multiply every element in the array by 2:"
]
},
{
"cell_type": "code",
"execution_count": 37,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [
{
"data": {
"text/plain": [
"array([2, 4])"
]
},
"execution_count": 37,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Numpy Array Multiplication\n",
"\n",
"z = 2 * y\n",
"z"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
" This is equivalent to multiplying a vector by a scaler: "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<h3 id=\"prod\">Product of Two Numpy Arrays</h3>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Consider the following array <code>u</code>:"
]
},
{
"cell_type": "code",
"execution_count": 38,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [
{
"data": {
"text/plain": [
"array([1, 2])"
]
},
"execution_count": 38,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Create a numpy array\n",
"\n",
"u = np.array([1, 2])\n",
"u"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Consider the following array <code>v</code>:"
]
},
{
"cell_type": "code",
"execution_count": 39,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [
{
"data": {
"text/plain": [
"array([3, 2])"
]
},
"execution_count": 39,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Create a numpy array\n",
"\n",
"v = np.array([3, 2])\n",
"v"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
" The product of the two numpy arrays <code>u</code> and <code>v</code> is given by:"
]
},
{
"cell_type": "code",
"execution_count": 40,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [
{
"data": {
"text/plain": [
"array([3, 4])"
]
},
"execution_count": 40,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Calculate the production of two numpy arrays\n",
"\n",
"z = u * v\n",
"z"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<h3 id=\"dot\">Dot Product</h3>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The dot product of the two numpy arrays <code>u</code> and <code>v</code> is given by:"
]
},
{
"cell_type": "code",
"execution_count": 41,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [
{
"data": {
"text/plain": [
"7"
]
},
"execution_count": 41,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Calculate the dot product\n",
"\n",
"np.dot(u, v)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<h3 id=\"cons\">Adding Constant to a Numpy Array</h3>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Consider the following array: "
]
},
{
"cell_type": "code",
"execution_count": 42,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [
{
"data": {
"text/plain": [
"array([ 1, 2, 3, -1])"
]
},
"execution_count": 42,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Create a constant to numpy array\n",
"\n",
"u = np.array([1, 2, 3, -1]) \n",
"u"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Adding the constant 1 to each element in the array:"
]
},
{
"cell_type": "code",
"execution_count": 43,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [
{
"data": {
"text/plain": [
"array([2, 3, 4, 0])"
]
},
"execution_count": 43,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Add the constant to array\n",
"\n",
"u + 1"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
" The process is summarised in the following animation:"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<img src=\"https://s3-api.us-geo.objectstorage.softlayer.net/cf-courses-data/CognitiveClass/PY0101EN/Chapter%205/Images/NumOneAdd.gif\" width=\"500\" />"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<hr>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<h2 id=\"math\">Mathematical Functions</h2>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
" We can access the value of pie in numpy as follows :"
]
},
{
"cell_type": "code",
"execution_count": 44,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [
{
"data": {
"text/plain": [
"3.141592653589793"
]
},
"execution_count": 44,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# The value of pie\n",
"\n",
"np.pi"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
" We can create the following numpy array in Radians:"
]
},
{
"cell_type": "code",
"execution_count": 45,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [],
"source": [
"# Create the numpy array in radians\n",
"\n",
"x = np.array([0, np.pi/2 , np.pi])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can apply the function <code>sin</code> to the array <code>x</code> and assign the values to the array <code>y</code>; this applies the sine function to each element in the array: "
]
},
{
"cell_type": "code",
"execution_count": 46,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [
{
"data": {
"text/plain": [
"array([0.0000000e+00, 1.0000000e+00, 1.2246468e-16])"
]
},
"execution_count": 46,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Calculate the sin of each elements\n",
"\n",
"y = np.sin(x)\n",
"y"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<hr>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<h2 id=\"lin\">Linspace</h2>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
" A useful function for plotting mathematical functions is \"linespace\". Linespace returns evenly spaced numbers over a specified interval. We specify the starting point of the sequence and the ending point of the sequence. The parameter \"num\" indicates the Number of samples to generate, in this case 5:"
]
},
{
"cell_type": "code",
"execution_count": 47,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [
{
"data": {
"text/plain": [
"array([-2., -1., 0., 1., 2.])"
]
},
"execution_count": 47,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Makeup a numpy array within [-2, 2] and 5 elements\n",
"\n",
"np.linspace(-2, 2, num=5)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"If we change the parameter <code>num</code> to 9, we get 9 evenly spaced numbers over the interval from -2 to 2: "
]
},
{
"cell_type": "code",
"execution_count": 48,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [
{
"data": {
"text/plain": [
"array([-2. , -1.5, -1. , -0.5, 0. , 0.5, 1. , 1.5, 2. ])"
]
},
"execution_count": 48,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Makeup a numpy array within [-2, 2] and 9 elements\n",
"\n",
"np.linspace(-2, 2, num=9)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can use the function line space to generate 100 evenly spaced samples from the interval 0 to 2π: "
]
},
{
"cell_type": "code",
"execution_count": 49,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [],
"source": [
"# Makeup a numpy array within [0, 2π] and 100 elements \n",
"\n",
"x = np.linspace(0, 2*np.pi, num=100)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can apply the sine function to each element in the array <code>x</code> and assign it to the array <code>y</code>: "
]
},
{
"cell_type": "code",
"execution_count": 50,
"metadata": {},
"outputs": [],
"source": [
"# Calculate the sine of x list\n",
"\n",
"y = np.sin(x)"
]
},
{
"cell_type": "code",
"execution_count": 51,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [
{
"data": {
"text/plain": [
"[<matplotlib.lines.Line2D at 0x7f5b3659b278>]"
]
},
"execution_count": 51,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAYIAAAD4CAYAAADhNOGaAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAAgAElEQVR4nO3dd3yV9fn/8deVRSAkzARCAgTIgACyIoIDZQqoRa21YrX4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1qmuOlkaqeszJTIHUIugLZKhqpqoWAzOBUQ5nqhVV/QY44nSO86Wq+1R1tev9CSrmp4hzNlXNaYV812Ko6+VTv0mJSDxwFTDV6SyBSESigAHANABVLXa6CEBgFYI4ILvScg4+9EPI34hIAtALWO5sktpxXVZZQ8W0ql+qqk/lB/4F/A4odzqIGxSYKyKrRGSs02FqqSOQC7ziujw3VUQcn8g5kAqBVLPOp36b8xci0hh4H7hHVY87nac2VLVMVXtSMfd2XxHxmUt0InI1cFBVVzmdxU2XqGpvYAQwznXJ1FeEAL2ByaraCzgJOH6/MpAKQQ7QttJyPLDXoSwBy3Vt/X3gDVX9wOk858vVnF8IDHc4Sm1cAvzIdY19JjBIRF53NlLtqepe19eDwCwqLvv6ihwgp1JL8j0qCoOjAqkQrASSRKSD6wbNTcDHDmcKKK6brdOAzar6rNN5aktEokWkqet9Q2AIsMXZVDWnqn9Q1XhVTaDi3/98Vb3F4Vi1IiIRro4GuC6pDAN8phedqu4HskUkxbVqMOB4Z4kQpwPUF1UtFZHxwBwgGJiuqhsdjlUrIvIWcAXQUkRygD+p6jRnU9XKJcCtwHrXdXaAB1V1toOZaiMWmOHqgRYEvKOqPtkF04e1AmZV/E5BCPCmqn7hbKRauwt4w/ULaSbw/xzOEzjdR40xxlQvkC4NGWOMqYYVAmOMCXBWCIwxJsBZITDGmABnhcAYYwKcFQJjjAlwVgiMMSbA/X+pJ0Fp45JVoQAAAABJRU5ErkJggg==\n",
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"# Plot the result\n",
"\n",
"plt.plot(x, y)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<hr>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<h2 id=\"quiz\">Quiz on 1D Numpy Array</h2>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Implement the following vector subtraction in numpy: u-v"
]
},
{
"cell_type": "code",
"execution_count": 52,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[ 1 -1]\n"
]
}
],
"source": [
"# Write your code below and press Shift+Enter to execute\n",
"\n",
"u = np.array([1, 0])\n",
"v = np.array([0, 1])\n",
"print(u-v)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Double-click __here__ for the solution.\n",
"\n",
"<!-- Your answer is below:\n",
"u - v\n",
"-->"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<hr>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Multiply the numpy array z with -2:"
]
},
{
"cell_type": "code",
"execution_count": 53,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([4, 8])"
]
},
"execution_count": 53,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Write your code below and press Shift+Enter to execute\n",
"\n",
"z = np.array([2, 4])\n",
"z*2"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Double-click __here__ for the solution.\n",
"\n",
"<!-- Your answer is below:\n",
"-2 * z\n",
"-->"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<hr>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Consider the list <code>[1, 2, 3, 4, 5]</code> and <code>[1, 0, 1, 0, 1]</code>, and cast both lists to a numpy array then multiply them together:"
]
},
{
"cell_type": "code",
"execution_count": 54,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([1, 0, 3, 0, 5])"
]
},
"execution_count": 54,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Write your code below and press Shift+Enter to execute\n",
"k = np.array([1,2,3,4,5])\n",
"l = np.array([1,0,1,0,1])\n",
"k*l"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Double-click __here__ for the solution.\n",
"\n",
"<!-- Your answer is below:\n",
"a = np.array([1, 2, 3, 4, 5])\n",
"b = np.array([1, 0, 1, 0, 1])\n",
"a * b\n",
"-->"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<hr>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Convert the list <code>[-1, 1]</code> and <code>[1, 1]</code> to numpy arrays <code>a</code> and <code>b</code>. Then, plot the arrays as vectors using the fuction <code>Plotvec2</code> and find the dot product:"
]
},
{
"cell_type": "code",
"execution_count": 55,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0"
]
},
"execution_count": 55,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAYQAAAD8CAYAAAB3u9PLAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAAaRElEQVR4nO3deZxV9X3/8dd7ADUgBJRFVjUNiStuE5ZIEtJEC9RGbdVos/AwaalG09j6aPUXo2nSJWnSxpa6UJpYNRqINkGpYhBsUEnFOFjZBAUJygjKZnDBhYHP74/vQcfxDjPDPXPPnZn38/GYx5xz73fu98N3hvu+Z/seRQRmZmY1RRdgZmbVwYFgZmaAA8HMzDIOBDMzAxwIZmaWcSCYmRmQQyBIGi7pl5JWSVop6Wsl2kjSNElrJS2TdHK5/ZqZWb665/AaDcDlEfG4pN7AEknzI+LJRm0mASOzrzHAjdl3MzOrEmVvIUTEpoh4PFt+BVgFDG3S7Ezg1kgWA30lDS63bzMzy08eWwhvk3QEcBLwaJOnhgIbGq3XZ49tKvEaU4GpAL169TrlqKOOyrNEM7NObcmSJVsjYsD+/GxugSDpYOBnwGUR8XLTp0v8SMk5MyJiBjADoLa2Nurq6vIq0cys05P07P7+bC5nGUnqQQqD2yPi5yWa1APDG60PAzbm0beZmeUjj7OMBPwIWBURP2im2Rzgi9nZRmOBHRHxnt1FZmZWnDx2GZ0KfAFYLumJ7LGvAyMAImI6MBeYDKwFdgIX5tC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NLjKaqwKEfEQsH0fTYoeS6BVdRYuIjZFxOPZ8iukMziHNmnW5vGsmkBo4kukZGuq1DQYTQehWgRwv6Ql2XQc1agaxnNQRGyC9EcODGymXRHj2ZrxKXoMW9v/OElLJd0n6djKlNZmRY9lW1TNeEo6AjgJeLTJU20ezzznMmpRpafB2F+tqbMVTo2IjZIGkq7TWJ198shNDnUWPp5teJl2H88SWjM+FRnDfWhN/48Dh0fEq5ImA3cBI9u9srYreixbq2rGU9LBwM+AyyLi5aZPl/iRfY5nRQMhOsg0GC3V2crX2Jh93yxpNmnTPtc3sBzqLHw8Jb0oaXBEbMo2Zzc38xrtPp4ltGZ8ip6apcX+G79RRMRcSTdI6h8R1TZJW9Fj2SrVMp6SepDC4PaI+HmJJm0ez6rZZaRONA2GpF6Seu9dJh0wr8ZZW6thPOcAU7LlKcB7tmwKHM/WjM8c4IvZGR1jgR17d4FVSIs1SjpMkrLl0aT/99sqWGNrFT2WrVIN45n1/yNgVUT8oJlmbR/PIo+UNzkivpa0v+uJ7Gt69vgQYG6TI+dPk86suKqAOs8mJe+bwIvAvKZ1ks74WJp9razWOqtkPA8FHgDWZN8PqabxLDU+wEXARdmySDeAegZYzj7OPCuwxkuzcVtKOmHjo5WuMatjJrAJ2JX9bX652saylXUWPp7AeNLun2WN3jMnlzuenrrCzMyAKtplZGZmxXIgmJkZ4EAwM7OMA8HMzAAHgpmZZRwIZmYGOBDMzCzz/wHtOhx1/spgMQAAAABJRU5ErkJggg==\n",
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"# Write your code below and press Shift+Enter to execute\n",
"a = np.array([-1,1])\n",
"b = np.array([1,1])\n",
"Plotvec2(a,b)\n",
"np.dot(a,b)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Double-click __here__ for the solution.\n",
"\n",
"<!-- Your answer is below:\n",
"a = np.array([-1, 1])\n",
"b = np.array([1, 1])\n",
"Plotvec2(a, b)\n",
"print(\"The dot product is\", np.dot(a,b))\n",
"-->"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<hr>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Convert the list <code>[1, 0]</code> and <code>[0, 1]</code> to numpy arrays <code>a</code> and <code>b</code>. Then, plot the arrays as vectors using the function <code>Plotvec2</code> and find the dot product:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Write your code below and press Shift+Enter to execute"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Double-click __here__ for the solution.\n",
"\n",
"<!-- \n",
"a = np.array([1, 0])\n",
"b = np.array([0, 1])\n",
"Plotvec2(a, b)\n",
"print(\"The dot product is\", np.dot(a, b))\n",
" -->"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<hr>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Convert the list <code>[1, 1]</code> and <code>[0, 1]</code> to numpy arrays <code>a</code> and <code>b</code>. Then plot the arrays as vectors using the fuction <code>Plotvec2</code> and find the dot product:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Write your code below and press Shift+Enter to execute"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Double-click __here__ for the solution.\n",
"\n",
"<!-- \n",
"a = np.array([1, 1])\n",
"b = np.array([0, 1])\n",
"Plotvec2(a, b)\n",
"print(\"The dot product is\", np.dot(a, b))\n",
"print(\"The dot product is\", np.dot(a, b))\n",
" -->"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<hr>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Why are the results of the dot product for <code>[-1, 1]</code> and <code>[1, 1]</code> and the dot product for <code>[1, 0]</code> and <code>[0, 1]</code> zero, but not zero for the dot product for <code>[1, 1]</code> and <code>[0, 1]</code>? <p><i>Hint: Study the corresponding figures, pay attention to the direction the arrows are pointing to.</i></p>"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Write your code below and press Shift+Enter to execute"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Double-click __here__ for the solution.\n",
"\n",
"<!-- \n",
"The vectors used for question 4 and 5 are perpendicular. As a result, the dot product is zero. \n",
"-->"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<hr>\n",
"<h2>The last exercise!</h2>\n",
"<p>Congratulations, you have completed your first lesson and hands-on lab in Python. However, there is one more thing you need to do. The Data Science community encourages sharing work. The best way to share and showcase your work is to share it on GitHub. By sharing your notebook on GitHub you are not only building your reputation with fellow data scientists, but you can also show it off when applying for a job. Even though this was your first piece of work, it is never too early to start building good habits. So, please read and follow <a href=\"https://cognitiveclass.ai/blog/data-scientists-stand-out-by-sharing-your-notebooks/\" target=\"_blank\">this article</a> to learn how to share your work.\n",
"<hr>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<div class=\"alert alert-block alert-info\" style=\"margin-top: 20px\">\n",
"<h2>Get IBM Watson Studio free of charge!</h2>\n",
" <p><a href=\"https://cocl.us/NotebooksPython101bottom\"><img src=\"https://s3-api.us-geo.objectstorage.softlayer.net/cf-courses-data/CognitiveClass/PY0101EN/Ad/BottomAd.png\" width=\"750\" align=\"center\"></a></p>\n",
"</div>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<h3>About the Authors:</h3> \n",
"<p><a href=\"https://www.linkedin.com/in/joseph-s-50398b136/\" target=\"_blank\">Joseph Santarcangelo</a> is a Data Scientist at IBM, and holds a PhD in Electrical Engineering. His research focused on using Machine Learning, Signal Processing, and Computer Vision to determine how videos impact human cognition. Joseph has been working for IBM since he completed his PhD.</p>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Other contributors: <a href=\"www.linkedin.com/in/jiahui-mavis-zhou-a4537814a\">Mavis Zhou</a>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<hr>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<p>Copyright &copy; 2018 IBM Developer Skills Network. This notebook and its source code are released under the terms of the <a href=\"https://cognitiveclass.ai/mit-license/\">MIT License</a>.</p>"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python",
"language": "python",
"name": "conda-env-python-py"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.10"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment