Skip to content

Instantly share code, notes, and snippets.

@netappzone
Created May 2, 2019 13:03
Show Gist options
  • Save netappzone/b262238ec47eee28a975413d984e8f81 to your computer and use it in GitHub Desktop.
Save netappzone/b262238ec47eee28a975413d984e8f81 to your computer and use it in GitHub Desktop.
Created on Cognitive Class Labs
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"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": [
"<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": [
"<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": 1,
"metadata": {
"collapsed": true
},
"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": 34,
"metadata": {
"collapsed": 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": null,
"metadata": {
"collapsed": 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": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"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": 2,
"metadata": {
"collapsed": 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": 3,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"array([0, 1, 2, 3, 4])"
]
},
"execution_count": 3,
"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": 4,
"metadata": {
"collapsed": 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": 5,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"numpy.ndarray"
]
},
"execution_count": 5,
"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": 6,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"dtype('int64')"
]
},
"execution_count": 6,
"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": 7,
"metadata": {
"collapsed": 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": 8,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"numpy.ndarray"
]
},
"execution_count": 8,
"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": 9,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"dtype('float64')"
]
},
"execution_count": 9,
"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": 10,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"array([20, 1, 2, 3, 4])"
]
},
"execution_count": 10,
"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": 11,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"array([100, 1, 2, 3, 4])"
]
},
"execution_count": 11,
"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": 12,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"array([100, 1, 2, 3, 0])"
]
},
"execution_count": 12,
"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": 13,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"array([1, 2, 3])"
]
},
"execution_count": 13,
"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": 14,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"array([100, 1, 2, 300, 400])"
]
},
"execution_count": 14,
"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": 15,
"metadata": {
"collapsed": true
},
"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": 16,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"array([100, 2, 300])"
]
},
"execution_count": 16,
"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": 17,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"array([100000, 1, 100000, 100000, 400])"
]
},
"execution_count": 17,
"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": 18,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"array([0, 1, 2, 3, 4])"
]
},
"execution_count": 18,
"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": 19,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"5"
]
},
"execution_count": 19,
"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": 20,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"1"
]
},
"execution_count": 20,
"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": 21,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"(5,)"
]
},
"execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Get the shape/size of numpy array\n",
"\n",
"a.shape"
]
},
{
"cell_type": "code",
"execution_count": 24,
"metadata": {
"collapsed": true
},
"outputs": [
{
"data": {
"text/plain": [
"array([ 1, -1, 1, -1])"
]
},
"execution_count": 24,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Create a numpy array\n",
"\n",
"a = np.array([1, -1, 1, -1])\n",
"a"
]
},
{
"cell_type": "code",
"execution_count": 25,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"0.0"
]
},
"execution_count": 25,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Get the mean of numpy array\n",
"\n",
"mean = a.mean()\n",
"mean"
]
},
{
"cell_type": "code",
"execution_count": 26,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"1.0"
]
},
"execution_count": 26,
"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": 27,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"array([-1, 2, 3, 4, 5])"
]
},
"execution_count": 27,
"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": 28,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"5"
]
},
"execution_count": 28,
"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": 29,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"-1"
]
},
"execution_count": 29,
"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": 30,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"array([1, 0])"
]
},
"execution_count": 30,
"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": 31,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"array([0, 1])"
]
},
"execution_count": 31,
"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": 32,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"array([1, 1])"
]
},
"execution_count": 32,
"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",
"exec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cvkDv8sa/Tv5bhC96cfXWFmZkCJHTIyM7PsOBDMzAxwIJiZWcKBYGZmgAPBzMwSDgQzMwMcCGZmlvj/zAGvMR/PEi0AAAAASUVORK5CYII=\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
},
"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
},
"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
},
"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
},
"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
},
"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
},
"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
},
"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
},
"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
},
"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": 47,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"array([0. , 1.57079633, 3.14159265])"
]
},
"execution_count": 47,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Create the numpy array in radians\n",
"\n",
"x = np.array([0, np.pi/2 , np.pi])\n",
"x"
]
},
{
"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": 48,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"array([0.0000000e+00, 1.0000000e+00, 1.2246468e-16])"
]
},
"execution_count": 48,
"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": 49,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"array([-2., -1., 0., 1., 2.])"
]
},
"execution_count": 49,
"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": 50,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"array([-2. , -1.5, -1. , -0.5, 0. , 0.5, 1. , 1.5, 2. ])"
]
},
"execution_count": 50,
"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": 51,
"metadata": {
"collapsed": 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": 52,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# Calculate the sine of x list\n",
"\n",
"y = np.sin(x)"
]
},
{
"cell_type": "code",
"execution_count": 53,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"[<matplotlib.lines.Line2D at 0x7f0db4cb8a20>]"
]
},
"execution_count": 53,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAYYAAAD8CAYAAABzTgP2AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4zLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvnQurowAAIABJREFUeJzt3Xd4lfX9//HnO5sMEkLCyoAAYW9iUHAwBSeKC6yKOHBba2vFr7Zaq63WVlHEgThwax1AFWWjKCIEZEPIYCSsJISRQfbn90cO/pKYkHFOcp/xflzXuXLOfe475xVa88rnXh8xxqCUUkqd5mV1AKWUUs5Fi0EppVQ1WgxKKaWq0WJQSilVjRaDUkqparQYlFJKVaPFoJRSqhotBqWUUtVoMSillKrGx+oATREREWG6dOlidQyllHIpGzZsyDHGRNa3nksWQ5cuXUhKSrI6hlJKuRQR2deQ9XRXklJKqWq0GJRSSlWjxaCUUqoaLQallFLVaDEopZSqxiHFICJviUiWiGyr430RkZdEJFVEtojIkCrvTRWRFNtjqiPyKKWUajpHjRjeASac4f2LgHjbYzrwKoCIhAOPA8OAROBxEWnjoExKKaWawCHXMRhjvheRLmdYZSLwrqmcR3StiISJSEdgJLDUGJMLICJLqSyYjxyRSzVOQXEZqVn5pGXnc7ywlOKyCorLymnl60271v60Cwmga2QQHUNbWR1VKdWMWuoCtyggo8rrTNuyupb/hohMp3K0QWxsbPOk9DCnSspZm36UlclZfLc7m31HCxu0XafQAAZ3bsOIbhFc3L8DYYF+zZxUKdWSWqoYpJZl5gzLf7vQmDnAHICEhIRa11ENs+vwSd79aR/z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gcZTGGAFcbttH/zEwWkTetzZS4xljDtq+ZgFfUrmb2FVkAplVRpqfUVkUTsWTimE9EC8icbYDPpOBhRZn8hi2A7dvAjuNMc9bnacpRCRSRMJsz1sBY4Fd1qZqOGPMI8aYaGNMFyr//7/CGHODxbEaRUSCbCcvYNsFcyHgMmfqGWMOAxki0tO2aAzgdCdg+FgdoKUYY8pE5F5gMeANvGWM2W5xrAYTkY+AkUCEiGQCjxtj3rQ2VaOMAG4Ettr20QP8nzFmkYWZGqsjMM92hpsX8KkxxiVP+XRh7YEvK//OwAf40BjzrbWRGu0+4APbH6jpwDSL8/yGx5yuqpRSqmE8aVeSUkqpBtBiUEopVY0Wg1JKqWq0GJRSSlWjxaCUUqoaLQallFLVaDEopZSqRotBKaVUNf8PSkPz2rqC2OEAAAAASUVORK5CYII=\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": 54,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([ 1, -1])"
]
},
"execution_count": 54,
"metadata": {},
"output_type": "execute_result"
}
],
"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",
"z = u - v\n",
"z"
]
},
{
"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": 55,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([4, 8])"
]
},
"execution_count": 55,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Write your code below and press Shift+Enter to execute\n",
"\n",
"z = np.array([2, 4])\n",
"y = z*2\n",
"y"
]
},
{
"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": 56,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([1, 0, 3, 0, 5])"
]
},
"execution_count": 56,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Write your code below and press Shift+Enter to execute\n",
"a = np.array( [1, 2, 3, 4, 5])\n",
"b = np.array( [1, 0, 1, 0, 1])\n",
"c = a*b\n",
"c"
]
},
{
"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": 58,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"0\n"
]
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAYQAA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HOlt9W8KW69yKlxmUbc+9gIckzY+IF/KpsEkt2T4V2YbNaEkNvwUmRcR7ks4g7dV8udUr2zrVsC1b4mlgj4h4S9KxwN3AkCIKkbQD8Gvg3Ih4o/HTJX5ki9uz4oEQbWAqjOZqbOFrLM++r5Q0mbRbn2sg5FBnRaYV2VKdkl6T1DciVmS7syubeI3N23OppJmkT0StHQgt2T6b29RL6gzsROUPNzRbZ0SsabD6S9I5umrTJqa5afjGGxFTJV0lqXdEVHTSO0ldSGFwa0T8pkSTrd6eVXXISO1kKgxJ3SXtuHmZdLK8GmdtrYZtOQUYly2PAz6xZyOpl6Su2XJvYATwTAVqa8n2aVj/GOChJj7ItKZm62x07Ph40jHnajMF+FY2OmYYsG7z4cRqImn3zeeJJB1Geh9ds+Wfyr0GAdcBiyLiF0002/rtWeSZ8hJnzpeQjnnNyb42j97oB0xtdPb8edInxAsrXONJpOR9D3gNmNa4RtJoj7nZ18JK19jSOovelln/uwAPAouz7ztnj9cC12bLnwfmZ9tzPnBaBev7xPYBLiF9aAHYHrgz+9v9I7BXpbdhC+u8NPtbnAs8DOxTQI2TgBXAB9nf5mnAGcAZ2fMi3Uzrhez33OQovoLrPKfBtpwFfL6AGkeSDv/Ma/B+eWy529NTV5iZGVBlh4zMzKw4DgQzMwMcCGZmlnEgmJkZ4EAwM7OMA8HMzAAHgpmZZf4/wC8P4fc4oW8AAAAASUVORK5CYII=\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",
"print(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": 60,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"4\n"
]
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAYsAAAEGCAYAAACUzrmNAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4zLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvnQurowAAHMBJREFUeJzt3XmcHVWd/vHPQxIIO0gSE0gyAdkEN7CHfRAVGIjKKmNAMSAaERhwXBBkBMURdXQEEQSDMICgxB9rhGgExAGUIE0mBLIIIaCJCVkIhIRgyPL9/XGqp5vmdlcnt+6te9PP+/XqV9Wte3LPl+qmn66qU6cUEZiZmXVno7ILMDOzxuewMDOzXA4LMzPL5bAwM7NcDgszM8vlsDAzs1wOCzMzy+WwMDOzXA4LM2saku6U9LikaZLGlF1PbyLfwW1mzULSWyJiiaRNgceA90XEi2XX1Rv0LbsAM7N1cLakY7P1YcAugMOiDhwWZtYUJB0CHArsHxErJP0e6F9qUb2Ir1mYWbPYGngpC4rdgf3KLqg3cViYWbP4DdBX0lTgm8CkkuvpVXyB28zMcvnIwszMclUdFpKGSXpA0oxs7PM5FdpI0uWSZkmaKmnvavs1M7P6KWI01GrgixExWdKWwOOS7o2I6R3aHEka4rYLsC9wVbY0M7MmUPWRRUTMj4jJ2foyYAawQ6dmRwM3RjIJ2EbSkGr7NjOz+ij0PgtJI4C9gEc7vbUDMKfD67nZtvkVPmMMMAZg8803f+/uu+9eZIlm1ihWrYLZs2H5c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us4ZJakfKShujojbKzQpdH821GkobSDTh0jaXNKWbeukC/eNOCFiI+zL8cDobH008KYjIknbStokWx8AHAhMr0NtPdk/Hev/KPC7Lv7IqaXcOjudqz6KdI670YwHPpmN4tkPWNp2irKRSBrcdl1K0j6k36Mvdv+vCq9BwLXAjIj4QRfNit2fZV7Rr3CFfxbpHNuU7KttlMn2wIROV/mfJv1leUGdazyWlNgrgQXAxM41kkalPJF9Tat3jT2ts+x9mfW/HXA/8Ey2fEu2vQX4abZ+APBktj+fBE6rY31v2j/AxaQ/aAD6A/8v+9n9E7BTvfdhD+v8dvaz+ATwALB7CTX+ApgPrMp+Nk8DTgdOz94X6UFpz2bf5y5HG5Zc51kd9uUk4IASajyIdEppaofflyNruT99B7eZmeVqqNNQZmbWmBwWZmaWy2FhZma5HBZmZpbLYWFmZrkcFmZmlsthYWZmuRwWZmaW6/8DUeiEcjSJfrYAAAAASUVORK5CYII=\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,2])\n",
"b = np.array([2,1])\n",
"Plotvec2 (a,b)\n",
"print(np.dot(a,b))"
]
},
{
"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": 61,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1\n"
]
},
{
"data": {
"image/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I2Jv4EM0fndDr3Vm5uYusz+iOEbXagbFbW66/uLNzDkRcX1EjMrMht70LiJGUoTBbZn5sxpN+r09W2qXUQyRW2FExIERcfDOaYqD5a1419ZW2JazgcvK6cuAD4xsIuKwiNi3nB4FTAZWNaC2vmyfrvVfDDzawx8yA6nXOrvtO76QYp9zq5kNfKk8O2YSsHXn7sRWEhFH7zxOFBFnUvwe3bz7T1VeQwA3Aasz8597aNb/7dnMI+U1jpyvpdjn9UT52nn2xjHAnG5Hz5+h+AvxmgbX+BmK5H0HeAl4uHuNFGd7LCtfKxtdY1/rbPa2LPs/AvglsKb8enj5fhtwYzn9x8CKcnuuAC5vYH0f2D7Atyn+aAHYD7ir/Nn9D+DERm/DPtb5f8ufxWXAr4CTmlDj7cBG4L3yZ/Ny4GvA18rlQfEwrWfL73OPZ/E1uc4ru2zLRcAfN6HGcyh2/yzv8vtyar3b01tXSJKAFttlJElqHgNBkgQYCJKkkoEgSQIMBElSyUCQJAEGgiSp9P8BiurYhWJP9EQAAAAASUVORK5CYII=\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([0,1])\n",
"Plotvec2 (a,b)\n",
"print(np.dot(a,b))"
]
},
{
"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 3",
"language": "python",
"name": "python3"
},
"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.8"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment