Created
September 11, 2020 01:10
-
-
Save nsburrows/b83c183aab23a28fdb3ae30b972728b5 to your computer and use it in GitHub Desktop.
Created on Skills Network Labs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "cells": [ | |
| { | |
| "cell_type": "markdown", | |
| "metadata": {}, | |
| "source": [ | |
| "<div class=\"alert alert-block alert-info\" style=\"margin-top: 20px\">\n", | |
| " <a href=\"https://cocl.us/topNotebooksPython101Coursera\">\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": {}, | |
| "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": 2, | |
| "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": 3, | |
| "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": 4, | |
| "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": 5, | |
| "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": 6, | |
| "metadata": { | |
| "collapsed": false, | |
| "jupyter": { | |
| "outputs_hidden": false | |
| } | |
| }, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "array([0, 1, 2, 3, 4])" | |
| ] | |
| }, | |
| "execution_count": 6, | |
| "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": 7, | |
| "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": 8, | |
| "metadata": { | |
| "collapsed": false, | |
| "jupyter": { | |
| "outputs_hidden": false | |
| } | |
| }, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "numpy.ndarray" | |
| ] | |
| }, | |
| "execution_count": 8, | |
| "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": 9, | |
| "metadata": { | |
| "collapsed": false, | |
| "jupyter": { | |
| "outputs_hidden": false | |
| } | |
| }, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "dtype('int64')" | |
| ] | |
| }, | |
| "execution_count": 9, | |
| "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": 10, | |
| "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": 11, | |
| "metadata": { | |
| "collapsed": false, | |
| "jupyter": { | |
| "outputs_hidden": false | |
| } | |
| }, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "numpy.ndarray" | |
| ] | |
| }, | |
| "execution_count": 11, | |
| "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": 12, | |
| "metadata": { | |
| "collapsed": false, | |
| "jupyter": { | |
| "outputs_hidden": false | |
| } | |
| }, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "dtype('float64')" | |
| ] | |
| }, | |
| "execution_count": 12, | |
| "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": 13, | |
| "metadata": { | |
| "collapsed": false, | |
| "jupyter": { | |
| "outputs_hidden": false | |
| } | |
| }, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "array([20, 1, 2, 3, 4])" | |
| ] | |
| }, | |
| "execution_count": 13, | |
| "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": 14, | |
| "metadata": { | |
| "collapsed": false, | |
| "jupyter": { | |
| "outputs_hidden": false | |
| } | |
| }, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "array([100, 1, 2, 3, 4])" | |
| ] | |
| }, | |
| "execution_count": 14, | |
| "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": 15, | |
| "metadata": { | |
| "collapsed": false, | |
| "jupyter": { | |
| "outputs_hidden": false | |
| } | |
| }, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "array([100, 1, 2, 3, 0])" | |
| ] | |
| }, | |
| "execution_count": 15, | |
| "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": 16, | |
| "metadata": { | |
| "collapsed": false, | |
| "jupyter": { | |
| "outputs_hidden": false | |
| } | |
| }, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "array([1, 2, 3])" | |
| ] | |
| }, | |
| "execution_count": 16, | |
| "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": 35, | |
| "metadata": { | |
| "collapsed": false, | |
| "jupyter": { | |
| "outputs_hidden": false | |
| } | |
| }, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "array([1, 1])" | |
| ] | |
| }, | |
| "execution_count": 35, | |
| "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": 36, | |
| "metadata": { | |
| "collapsed": false, | |
| "jupyter": { | |
| "outputs_hidden": false | |
| } | |
| }, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYQAAAD8CAYAAAB3u9PLAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuMCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy86wFpkAAAACXBIWXMAAAsTAAALEwEAmpwYAAAYDklEQVR4nO3deZBdZbnv8e/TGRhCkCEJZCAQi3gheD0RW4ajUkTRCzlq9BRo1FLLKUI5FrcsuHIuUrcKC714LClEjCKDVyYZIySMCgHLYDqRQEgQGkxM6EBCQkI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iz8vGMiBciYmxmrimms2s72Uevj2cN3Rmfqh/N0mX/Hf9QZObciLgsIkZlZqM9pK3qseyWRhnPiBhGexj8JjNvqdGkx+PZMIeMYgA9BiMiRkTEyH8s037CvBGf2toI4zkH+Hyx/HngTTObCsezO+MzB/hccUXHCcCmfxwC6yNd1hgRh0ZEFMvH0f7//fo+rLG7qh7LbmmE8Sz6vwJYnpn/3kmzno9nlWfKdzkj3kr78a5Hi9flxfvjgLm7nDl/ivYrK86roM6P0568rwMvAHfvWiftV3wsKV5PNGqdDTKeBwP3A08XPw9qpPGsNT7AmcCZxXLQ/gVQzwCPs5srzyqs8evFuC2h/YKNf+7rGos6rgPWAFuL380vNdpYdrPOyscTeC/th38e6/A3c3q94+mjKyRJQAMdMpIkVctAkCQBBoIkqWAgSJIAA0GSVDAQJEmAgSBJKvx/c5+2+a6YW2wAAAAASUVORK5CYII=\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": 37, | |
| "metadata": { | |
| "collapsed": false, | |
| "jupyter": { | |
| "outputs_hidden": false | |
| } | |
| }, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "array([1, 2])" | |
| ] | |
| }, | |
| "execution_count": 37, | |
| "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": 38, | |
| "metadata": { | |
| "collapsed": false, | |
| "jupyter": { | |
| "outputs_hidden": false | |
| } | |
| }, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "array([2, 4])" | |
| ] | |
| }, | |
| "execution_count": 38, | |
| "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": 39, | |
| "metadata": { | |
| "collapsed": false, | |
| "jupyter": { | |
| "outputs_hidden": false | |
| } | |
| }, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "array([1, 2])" | |
| ] | |
| }, | |
| "execution_count": 39, | |
| "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": 40, | |
| "metadata": { | |
| "collapsed": false, | |
| "jupyter": { | |
| "outputs_hidden": false | |
| } | |
| }, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "array([3, 2])" | |
| ] | |
| }, | |
| "execution_count": 40, | |
| "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": 41, | |
| "metadata": { | |
| "collapsed": false, | |
| "jupyter": { | |
| "outputs_hidden": false | |
| } | |
| }, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "array([3, 4])" | |
| ] | |
| }, | |
| "execution_count": 41, | |
| "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": 42, | |
| "metadata": { | |
| "collapsed": false, | |
| "jupyter": { | |
| "outputs_hidden": false | |
| } | |
| }, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "7" | |
| ] | |
| }, | |
| "execution_count": 42, | |
| "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": 43, | |
| "metadata": { | |
| "collapsed": false, | |
| "jupyter": { | |
| "outputs_hidden": false | |
| } | |
| }, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "array([ 1, 2, 3, -1])" | |
| ] | |
| }, | |
| "execution_count": 43, | |
| "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": 44, | |
| "metadata": { | |
| "collapsed": false, | |
| "jupyter": { | |
| "outputs_hidden": false | |
| } | |
| }, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "array([2, 3, 4, 0])" | |
| ] | |
| }, | |
| "execution_count": 44, | |
| "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": 45, | |
| "metadata": { | |
| "collapsed": false, | |
| "jupyter": { | |
| "outputs_hidden": false | |
| } | |
| }, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "3.141592653589793" | |
| ] | |
| }, | |
| "execution_count": 45, | |
| "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": 46, | |
| "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": 47, | |
| "metadata": { | |
| "collapsed": false, | |
| "jupyter": { | |
| "outputs_hidden": false | |
| } | |
| }, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "array([0.0000000e+00, 1.0000000e+00, 1.2246468e-16])" | |
| ] | |
| }, | |
| "execution_count": 47, | |
| "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": 48, | |
| "metadata": { | |
| "collapsed": false, | |
| "jupyter": { | |
| "outputs_hidden": false | |
| } | |
| }, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "array([-2., -1., 0., 1., 2.])" | |
| ] | |
| }, | |
| "execution_count": 48, | |
| "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": 49, | |
| "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": 49, | |
| "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": 50, | |
| "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": 51, | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "# Calculate the sine of x list\n", | |
| "\n", | |
| "y = np.sin(x)" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "collapsed": false, | |
| "jupyter": { | |
| "outputs_hidden": false | |
| } | |
| }, | |
| "outputs": [], | |
| "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": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "array([ 1, -1])" | |
| ] | |
| }, | |
| "execution_count": 52, | |
| "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", | |
| "\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": 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 = z * 2\n", | |
| "z" | |
| ] | |
| }, | |
| { | |
| "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", | |
| "\n", | |
| "a = np.array([1, 2, 3, 4, 5])\n", | |
| "b = np.array([1, 0, 1, 0, 1])\n", | |
| "\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": [ | |
| "The dot product is 0\n" | |
| ] | |
| }, | |
| { | |
| "data": { | |
| "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYQAAAD8CAYAAAB3u9PLAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuMCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy86wFpkAAAACXBIWXMAAAsTAAALEwEAmpwYAAAaRElEQVR4nO3deZxV9X3/8dd7ADUgBJRFVjUNiStuE5ZIEtJEC9RGbd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ugYC+zYuwusQlqsUdJhkpQtjyb9v99WwRpbq+ixbJVqGM+s/x8BqyLiB800a/t4FnmkvMkR8bWk/V1PZF/Ts8eHAHObHDl/mnRmxVUF1Hk2KXnfBF4E5jWtk3TGx9Lsa2W11lkl43ko8ACwJvt+SDWNZ6nxAS4CLsqWRboB1DPAcvZx5lmBNV6ajdtS0gkbH610jVkdM4FNwK7sb/PL1TaWrayz8PEExpN2/yxr9J45udzx9NQVZmYGVNEuIzMzK5YDwczMAAeCmZllHAhmZgY4EMzMLONAMDMzwIFgZmaZ/w/tOhx1vepY5gAAAABJRU5ErkJggg==\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", | |
| "\n", | |
| "Plotvec2(a,b)\n", | |
| "print(\"The dot product is\", 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": 59, | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "The dot product is 0\n" | |
| ] | |
| }, | |
| { | |
| "data": { | |
| "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYQAAAD8CAYAAAB3u9PLAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuMCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy86wFpkAAAACXBIWXMAAAsTAAALEwEAmpwYAAASdklEQVR4nO3dbYyd5X3n8e8PsBNhQIRggjF2kqrWBoicLQyOWaKVqyaRsaI1aUhF1GzcpNIoKKittC/CLkr6drsrVSqbB3ZWRQUJkVZpnVgb8xg1cpEgZUzBsbFdXMTGlt3YhMgBmZQ4/PfFudJMhzOeGZ97zhmb70c6OvfDde7rr4vx+XE/nlQVkiSdM+oCJEmLg4EgSQIMBElSYyBIkgADQZLUGAiSJKCDQEiyKsnfJtmbZE+SP+zTJknuSnIgya4k1w7arySpW+d1sI2TwH+pqqeTXAjsTPJoVT03pc1NwJr2+iDw9fYuSVokBt5DqKojVfV0m34F2AusnNZsM3Bf9TwJXJxkxaB9S5K608Uewr9K8h7gN4DvT1u1Ejg4Zf5QW3akzzbGgXGAZcuWXfe+972vyxIl6ay2c+fOl6pq+el8trNASHIB8NfAH1XVT6ev7vORvs/MqKoJYAJgbGysJicnuypRks56Sf7f6X62k6uMkiyhFwb3V9Xf9GlyCFg1Zf5K4HAXfUuSutHFVUYB/hzYW1V/OkOzbcBn2tVG64HjVfWmw0WSpNHp4pDRjcB/Bn6Q5Jm27L8BqwGq6m5gO7AJOACcAD7bQb+SpA4NHAhV9Tj9zxFMbVPAFwbtS5K0cLxTWZIEGAiSpMZAkCQBBoIkqTEQJEmAgSBJagwESRJgIEiSGgNBkgQYCJKkxkCQJAEGgiSpMRAkSYCBIElqDARJEmAgSJIaA0GSBBgIkqSmk0BIck+So0l2z7B+Q5LjSZ5pry930a8kqTsD/6Zy8xfAV4D7TtHm76rqYx31J0nqWC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AL8vP1t/v5iG8s51jny8QQ+RO/wz64p35mbBh1PH10hSQIW0SEjSdJoGQiSJMBAkCQ1BoIkCTAQJEmNgSBJAgwESVLz/wGswKsYaRlXhwAAAABJRU5ErkJggg==\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, 0])\n", | |
| "b = np.array([0, 1])\n", | |
| "\n", | |
| "Plotvec2(a, b)\n", | |
| "print(\"The dot product is\", 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": 60, | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "The dot product is 1\n" | |
| ] | |
| }, | |
| { | |
| "data": { | |
| "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYQAAAD8CAYAAAB3u9PLAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuMCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy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aCJAkwECRJpf8PUFrfmFkkuEAAAAAASUVORK5CYII=\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", | |
| "\n", | |
| "Plotvec2(a, b)\n", | |
| "print(\"The dot product is\", 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\n", | |
| "# -1 * 1 is -1 and 1 * 1 is 1 so 1 - 1 is 0\n", | |
| "# 1 * 0 is 0 and 0 * 1 is 0 so 0 + 0 is 0\n", | |
| "\n" | |
| ] | |
| }, | |
| { | |
| "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/bottemNotebooksPython101Coursera\"><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 © 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.11" | |
| } | |
| }, | |
| "nbformat": 4, | |
| "nbformat_minor": 4 | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment