diff --git a/Submodule1/Live_Demos/Day_1_Live_Demo_2_Introduction_to_NumPy.ipynb b/Submodule1/Live_Demos/Day_1_Live_Demo_2_Introduction_to_NumPy.ipynb index 77a2d73..7b64d9a 100644 --- a/Submodule1/Live_Demos/Day_1_Live_Demo_2_Introduction_to_NumPy.ipynb +++ b/Submodule1/Live_Demos/Day_1_Live_Demo_2_Introduction_to_NumPy.ipynb @@ -4,18 +4,25 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "#What is NumPy?\n", + "# What is NumPy?\n", + "\n", + "## Overview\n", + "\n", + "[NumPy](https://numpy.org/) is the fundamental package for scientific computing in Python. It is a Python library that provides a multidimensional array object, various derived objects (such as masked arrays and matrices), and an assortment of routines for fast operations on arrays, including mathematical, logical, shape manipulation, sorting, selecting, I/O, discrete Fourier transforms, basic linear algebra, basic statistical operations, random simulation and much more.\n", + "\n", + "## Learning Objectives\n", + "\n", + "* Understand the difference between one-, two- and n-dimensional arrays in NumPy\n", + "* Understand how to apply some linear algebra operations to n-dimensional arrays without using for-loops\n", + "* Understand axis and shape properties for n-dimensional arrays\n", + "\n", + "## Prerequisites\n", "\n", - "[NumPy](https://numpy.org/) is the fundamental package for scientific computing in Python. It is a Python library that provides a multidimensional array object, various derived objects (such as masked arrays and matrices), and an assortment of routines for fast operations on arrays, including mathematical, logical, shape manipulation, sorting, selecting, I/O, discrete Fourier transforms, basic linear algebra, basic statistical operations, random simulation and much more." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "#Prerequsites\n", "You’ll need to know a bit of Python. For a refresher, see the [Python tutorial](https://docs.python.org/tutorial/).\n", - "\n" + "\n", + "## Get Started\n", + "\n", + "To get started with this module, you will need to ensure that numpy is installed." ] }, { @@ -31,19 +38,8 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "#Learning objectives\n", - "* Understand the difference between one-, two- and n-dimensional arrays in NumPy;\n", - "\n", - "* Understand how to apply some linear algebra operations to n-dimensional arrays without using for-loops;\n", + "## Array Basics\n", "\n", - "* Understand axis and shape properties for n-dimensional arrays." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "#The Basics\n", "NumPy’s main object is the homogeneous multidimensional array (ndarray). It is a table of elements (usually numbers), all of the same type, indexed by a tuple of non-negative integers. In NumPy dimensions are called *axes*." ] }, @@ -51,7 +47,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "##An example NumPy ndarray\n" + "### An example NumPy ndarray" ] }, { @@ -75,9 +71,16 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "###**ndarray.ndim**\n", - "the number of axes of the array.\n", - "\n" + "### Array attributes" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### `ndarray.ndim`\n", + "\n", + "The number of axes of the array." ] }, { @@ -93,7 +96,8 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "###**ndarray.shape**\n", + "#### `ndarray.shape`\n", + "\n", "This is a tuple of integers indicating the size of the array in each dimension. For a matrix with n rows and m columns, shape will be (n,m). The length of the shape tuple is therefore the number of axes, ndim." ] }, @@ -110,8 +114,9 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "###**ndarray.size**\n", - "the total number of elements of the array. This is equal to the product of the elements of shape." + "#### `ndarray.size`\n", + "\n", + "The total number of elements of the array. This is equal to the product of the elements of shape." ] }, { @@ -127,8 +132,9 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "###**ndarray.dtype**\n", - "an object describing the type of the elements in the array. One can create or specify dtypes using standard Python types. Additionally NumPy provides types of its own. numpy.int32, numpy.int16, and numpy.float64 are some examples." + "#### `ndarray.dtype`\n", + "\n", + "An object describing the type of the elements in the array. One can create or specify dtypes using standard Python types. Additionally NumPy provides types of its own. numpy.int32, numpy.int16, and numpy.float64 are some examples." ] }, { @@ -144,8 +150,9 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "###**ndarray.itemsize**\n", - "the size in bytes of each element of the array. For example, an array of elements of type float64 has itemsize 8 (=64/8), while one of type complex32 has itemsize 4 (=32/8). It is equivalent to ndarray.dtype.itemsize." + "#### `ndarray.itemsize`\n", + "\n", + "The size in bytes of each element of the array. For example, an array of elements of type float64 has itemsize 8 (=64/8), while one of type complex32 has itemsize 4 (=32/8). It is equivalent to ndarray.dtype.itemsize." ] }, { @@ -161,9 +168,9 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "###**type()**\n", + "#### `type()`\n", "\n", - "the data type of the object." + "The data type of the object." ] }, { @@ -179,7 +186,8 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "##Creating Arrays\n", + "### Creating Arrays\n", + "\n", "You can create an array from a regular Python list or tuple using the array function. The type of the resulting array is deduced from the type of the elements in the sequences." ] }, @@ -332,7 +340,8 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "##Printing Arrays\n", + "### Printing Arrays\n", + "\n", "One-dimensional arrays are then printed as rows, bi-dimensionals as matrices and tri-dimensionals as lists of matrices." ] }, @@ -370,7 +379,8 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "#Basic Operations\n", + "### Basic Operations\n", + "\n", "Arithmetic operators on arrays apply elementwise. A new array is created and filled with the result." ] }, @@ -426,7 +436,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "the product operator * operates elementwise in NumPy arrays. The matrix product can be performed using the @ operator or the dot function or method:" + "The product operator * operates elementwise in NumPy arrays. The matrix product can be performed using the @ operator or the dot function or method:" ] }, { @@ -633,7 +643,8 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "#Universal Functions\n", + "### Universal Functions\n", + "\n", "NumPy provides familiar mathematical functions such as sin, cos, and exp. In NumPy, these are called “universal functions” (**ufunc**). Within NumPy, these functions operate elementwise on an array, producing an array as output." ] }, @@ -679,7 +690,8 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "#Indexing, Slicing and Iterating\n", + "### Indexing, Slicing and Iterating\n", + "\n", "One-dimensional arrays can be indexed, sliced and iterated over, much like lists and other Python sequences." ] }, @@ -799,7 +811,7 @@ "outputs": [], "source": [ "for row in b:\n", - " print(row)" + " print(row)" ] }, { @@ -823,8 +835,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "arrays can be indexed by arrays of integers and arrays of booleans.\n", - "\n" + "Arrays can be indexed by arrays of integers and arrays of booleans." ] }, { @@ -855,6 +866,19 @@ "source": [ "a[i] # the elements of `a` at the positions `i`" ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Conclusion\n", + "\n", + "In this module, we've learned about the basics of NumPy, including creating and manipulating arrays, using universal functions, and indexing/slicing arrays. These skills form the foundation for scientific computing in Python.\n", + "\n", + "## Clean up\n", + "\n", + "Remember to shut down your Jupyter Notebook instance when you're done to avoid unnecessary charges. You can do this by stopping the notebook instance from the Amazon SageMaker console." + ] } ], "metadata": {},