{ "cells": [ { "cell_type": "markdown", "id": "282fb346", "metadata": {}, "source": [ "# Python tutorial" ] }, { "cell_type": "markdown", "id": "9c4b8d73", "metadata": {}, "source": [ "**Course**: [_Analyse Numérique pour SV_](https://moodle.epfl.ch/course/info.php?id=) (MATH-2xx)\n", "**Professor**: _Simone Deparis_\n", "\n", "SSV, BA4, 2020" ] }, { "cell_type": "markdown", "id": "7e800b7a", "metadata": {}, "source": [ "Adapted from the `CS228` Python tutorial by by [Volodymyr Kuleshov](http://web.stanford.edu/~kuleshov/) and [Isaac Caswell](https://symsys.stanford.edu/viewing/symsysaffiliate/21335) and the version of Prof. Felix Naef for BIO-341." ] }, { "cell_type": "markdown", "id": "24365782", "metadata": {}, "source": [ "## Introduction" ] }, { "cell_type": "markdown", "id": "5b2a3e29", "metadata": {}, "source": [ "Python is a great general-purpose programming language on its own, but with the help of a few popular libraries (numpy, scipy, matplotlib) it becomes a powerful environment for scientific computing.\n", "\n", "We don't expect that many of you will have some experience with Python and numpy; this section will serve as a quick crash course both on the Python programming language and on the use of Python for scientific computing.\n", "\n", "Some of you may have previous knowledge in Matlab, in which case we also recommend the numpy for Matlab users page (https://docs.scipy.org/doc/numpy-1.15.0/user/numpy-for-matlab-users.html)." ] }, { "cell_type": "markdown", "id": "790b8467", "metadata": {}, "source": [ "In this tutorial, we will cover:\n", "\n", "* Basic Python: Basic data types (Containers, Lists, Dictionaries, Sets, Tuples), Functions\n", "* Numpy: Arrays, Array indexing, Datatypes, Array math, Broadcasting\n", "* Matplotlib: Plotting, Subplots, Images" ] }, { "cell_type": "markdown", "id": "daf262e0", "metadata": {}, "source": [ "## Basics of Python" ] }, { "cell_type": "markdown", "id": "cafdbb77", "metadata": {}, "source": [ "Python is a high-level, dynamically typed multiparadigm programming language. Python code is often said to be almost like pseudocode, since it allows you to express very powerful ideas in very few lines of code while being very readable. As an example, here is an implementation of the classic quicksort algorithm in Python:" ] }, { "cell_type": "code", "execution_count": null, "id": "dc1d1855", "metadata": {}, "outputs": [], "source": [ "def quicksort(arr):\n", " if len(arr) <= 1:\n", " return arr\n", " pivot = arr[len(arr) // 2]\n", " left = [x for x in arr if x < pivot]\n", " middle = [x for x in arr if x == pivot]\n", " right = [x for x in arr if x > pivot]\n", " return quicksort(left) + middle + quicksort(right)\n", "\n", "print(quicksort([3,6,8,10,1,2,1]))" ] }, { "cell_type": "markdown", "id": "dc8282ec", "metadata": {}, "source": [ "### Python versions" ] }, { "cell_type": "markdown", "id": "aaf39b03", "metadata": {}, "source": [ "There are currently two different supported versions of Python, 2.7 and 3.7. Somewhat confusingly, Python 3.0 introduced many backwards-incompatible changes to the language, so code written for 2.7 may not work under 3.7 and vice versa. For this class all code will use Python 3.7.\n", "\n", "You can check your Python version at the command line by running `python --version`." ] }, { "cell_type": "markdown", "id": "5f0b01d6", "metadata": {}, "source": [ "### Basic data types" ] }, { "cell_type": "markdown", "id": "8976830d", "metadata": {}, "source": [ "#### Numbers" ] }, { "cell_type": "markdown", "id": "ba77d9db", "metadata": {}, "source": [ "Integers and floats work as you would expect from other languages:" ] }, { "cell_type": "code", "execution_count": null, "id": "3ea3c5a6", "metadata": {}, "outputs": [], "source": [ "x = 3\n", "print(x, type(x))" ] }, { "cell_type": "code", "execution_count": null, "id": "84a3ca7a", "metadata": {}, "outputs": [], "source": [ "print(x + 1) # Addition;\n", "print(x - 1) # Subtraction;\n", "print(x * 2) # Multiplication;\n", "print(x**2) # Exponentiation;" ] }, { "cell_type": "code", "execution_count": null, "id": "ff70d562", "metadata": {}, "outputs": [], "source": [ "x += 1\n", "print(x) # Prints \"4\"\n", "x *= 2\n", "print(x) # Prints \"8\"" ] }, { "cell_type": "code", "execution_count": null, "id": "09add47f", "metadata": {}, "outputs": [], "source": [ "y = 2.5\n", "print(type(y)) # Prints \"\"\n", "print(y, y + 1, y * 2, y ** 2) # Prints \"2.5 3.5 5.0 6.25\"" ] }, { "cell_type": "markdown", "id": "80a99d03", "metadata": {}, "source": [ "Note that unlike many languages, Python does not have unary increment (x++) or decrement (x--) operators." ] }, { "cell_type": "markdown", "id": "350d890e", "metadata": {}, "source": [ "#### Booleans" ] }, { "cell_type": "markdown", "id": "5377ecb6", "metadata": {}, "source": [ "Python implements all of the usual operators for Boolean logic, but uses English words rather than symbols (`&&`, `||`, etc.):" ] }, { "cell_type": "code", "execution_count": null, "id": "e6ccf5c6", "metadata": {}, "outputs": [], "source": [ "t, f = True, False\n", "print(type(t)) # Prints \"\"" ] }, { "cell_type": "markdown", "id": "f087114e", "metadata": {}, "source": [ "Now we let's look at the operations:" ] }, { "cell_type": "code", "execution_count": null, "id": "576795d2", "metadata": {}, "outputs": [], "source": [ "print(t and f) # Logical AND;\n", "print(t or f) # Logical OR;\n", "print(not t) # Logical NOT;\n", "print(t != f) # Logical XOR;" ] }, { "cell_type": "markdown", "id": "cfca718d", "metadata": {}, "source": [ "#### Strings" ] }, { "cell_type": "code", "execution_count": null, "id": "6f692aa4", "metadata": {}, "outputs": [], "source": [ "hello = 'hello' # String literals can use single quotes\n", "world = \"world\" # or double quotes; it does not matter.\n", "print(hello, len(hello))" ] }, { "cell_type": "code", "execution_count": null, "id": "07f33c25", "metadata": {}, "outputs": [], "source": [ "hw = hello + ' ' + world # String concatenation\n", "print(hw) # prints \"hello world\"" ] }, { "cell_type": "markdown", "id": "00f8d6a4", "metadata": {}, "source": [ "String objects have a bunch of useful methods; for example:" ] }, { "cell_type": "code", "execution_count": null, "id": "3dfc4c01", "metadata": {}, "outputs": [], "source": [ "s = \"hello\"\n", "print(s.capitalize()) # Capitalize a string; prints \"Hello\"\n", "print(s.upper()) # Convert a string to uppercase; prints \"HELLO\"\n", "print(s.rjust(7)) # Right-justify a string, padding with spaces; prints \" hello\"\n", "print(s.center(7)) # Center a string, padding with spaces; prints \" hello \"\n", "print(s.replace('l', '(ell)')) # Replace all instances of one substring with another;\n", " # prints \"he(ell)(ell)o\"\n", "print(' world '.strip()) # Strip leading and trailing whitespace; prints \"world\"" ] }, { "cell_type": "markdown", "id": "667b1dcc", "metadata": {}, "source": [ "### Containers" ] }, { "cell_type": "markdown", "id": "2a1b72ee", "metadata": {}, "source": [ "Python includes several built-in container types: lists, dictionaries, sets, and tuples." ] }, { "cell_type": "markdown", "id": "fb1053b0", "metadata": {}, "source": [ "#### Lists" ] }, { "cell_type": "markdown", "id": "6b8ee616", "metadata": {}, "source": [ "A list is the Python equivalent of an array, but is resizeable and can contain elements of different types:" ] }, { "cell_type": "code", "execution_count": null, "id": "de584920", "metadata": {}, "outputs": [], "source": [ "xs = [3, 1, 2] # Create a list\n", "print(xs, xs[2])\n", "print(xs[-1]) # Negative indices count from the end of the list; prints \"2\"" ] }, { "cell_type": "code", "execution_count": null, "id": "2477623b", "metadata": {}, "outputs": [], "source": [ "xs[2] = 'foo' # Lists can contain elements of different types\n", "print(xs)" ] }, { "cell_type": "code", "execution_count": null, "id": "dab4ccd0", "metadata": {}, "outputs": [], "source": [ "xs.append('bar') # Add a new element to the end of the list\n", "print(xs) " ] }, { "cell_type": "code", "execution_count": null, "id": "0044e9a7", "metadata": {}, "outputs": [], "source": [ "x = xs.pop() # Remove and return the last element of the list\n", "print(x, xs) " ] }, { "cell_type": "markdown", "id": "22c25a60", "metadata": {}, "source": [ "#### Slicing" ] }, { "cell_type": "markdown", "id": "50333650", "metadata": {}, "source": [ "In addition to accessing list elements one at a time, Python provides concise syntax to access sublists; this is known as slicing:" ] }, { "cell_type": "code", "execution_count": null, "id": "94c9e50f", "metadata": {}, "outputs": [], "source": [ "nums = list(range(5)) # range is a built-in function that creates an interator of integers. \n", " #It has to be explicitely converted to a list to do slicing\n", "print(nums) # Prints \"[0, 1, 2, 3, 4]\"\n", "print(nums[2:4]) # Get a slice from index 2 to 4 (exclusive); prints \"[2, 3]\"\n", "print(nums[2:]) # Get a slice from index 2 to the end; prints \"[2, 3, 4]\"\n", "print(nums[:2]) # Get a slice from the start to index 2 (exclusive); prints \"[0, 1]\"\n", "print(nums[:]) # Get a slice of the whole list; prints [\"0, 1, 2, 3, 4]\"\n", "print(nums[:-1]) # Slice indices can be negative; prints [\"0, 1, 2, 3]\"\n", "nums[2:4] = [8, 9] # Assign a new sublist to a slice\n", "print(nums) # Prints \"[0, 1, 8, 9, 4]\"" ] }, { "cell_type": "markdown", "id": "4da38874", "metadata": {}, "source": [ "#### Loops" ] }, { "cell_type": "markdown", "id": "95812c1e", "metadata": {}, "source": [ "You can loop over the elements of a list like this:" ] }, { "cell_type": "code", "execution_count": null, "id": "965c7ecf", "metadata": {}, "outputs": [], "source": [ "animals = ['cat', 'dog', 'monkey']\n", "for animal in animals:\n", " print(animal)" ] }, { "cell_type": "markdown", "id": "35696e58", "metadata": {}, "source": [ "If you want access to the index of each element within the body of a loop, use the built-in `enumerate` function:" ] }, { "cell_type": "code", "execution_count": null, "id": "cc6355fb", "metadata": {}, "outputs": [], "source": [ "animals = ['cat', 'dog', 'monkey']\n", "for idx, animal in enumerate(animals):\n", " print(idx + 1, animal)" ] }, { "cell_type": "markdown", "id": "a58bc6a5", "metadata": {}, "source": [ "#### List comprehensions:" ] }, { "cell_type": "markdown", "id": "7230e38a", "metadata": {}, "source": [ "When programming, frequently we want to transform one type of data into another. As a simple example, consider the following code that computes square numbers:" ] }, { "cell_type": "code", "execution_count": null, "id": "2cd831d3", "metadata": {}, "outputs": [], "source": [ "nums = [0, 1, 2, 3, 4]\n", "squares = []\n", "for x in nums:\n", " squares.append(x ** 2)\n", "print(squares)" ] }, { "cell_type": "markdown", "id": "f2d3792c", "metadata": {}, "source": [ "You can make this code simpler using a list comprehension:" ] }, { "cell_type": "code", "execution_count": null, "id": "98a3e39a", "metadata": {}, "outputs": [], "source": [ "nums = [0, 1, 2, 3, 4]\n", "squares = [x ** 2 for x in nums]\n", "print(squares)" ] }, { "cell_type": "markdown", "id": "30a8f579", "metadata": {}, "source": [ "List comprehensions can also contain conditions:" ] }, { "cell_type": "code", "execution_count": null, "id": "2d6b876a", "metadata": {}, "outputs": [], "source": [ "nums = [0, 1, 2, 3, 4]\n", "even_squares = [x ** 2 for x in nums if x % 2 == 0]\n", "print(even_squares)" ] }, { "cell_type": "markdown", "id": "48da43d3", "metadata": {}, "source": [ "#### Dictionaries" ] }, { "cell_type": "markdown", "id": "1b6f55bc", "metadata": {}, "source": [ "A dictionary stores (key, value) pairs, similar to a `Map` in Java or an object in Javascript. You can use it like this:" ] }, { "cell_type": "code", "execution_count": null, "id": "d3ce77b0", "metadata": {}, "outputs": [], "source": [ "d = {'cat': 'cute', 'dog': 'furry'} # Create a new dictionary with some data\n", "print(d['cat']) # Get an entry from a dictionary; prints \"cute\"\n", "print('cat' in d) # Check if a dictionary has a given key; prints \"True\"" ] }, { "cell_type": "code", "execution_count": null, "id": "9b8d50c2", "metadata": {}, "outputs": [], "source": [ "d['fish'] = 'wet' # Set an entry in a dictionary\n", "print(d['fish']) # Prints \"wet\"" ] }, { "cell_type": "code", "execution_count": null, "id": "66051c12", "metadata": {}, "outputs": [], "source": [ "print(d['monkey']) # KeyError: 'monkey' not a key of d" ] }, { "cell_type": "code", "execution_count": null, "id": "8f4e1e93", "metadata": {}, "outputs": [], "source": [ "print(d.get('monkey', 'N/A')) # Get an element with a default; prints \"N/A\"\n", "print(d.get('fish', 'N/A')) # Get an element with a default; prints \"wet\"" ] }, { "cell_type": "code", "execution_count": null, "id": "6ea7eae1", "metadata": {}, "outputs": [], "source": [ "del(d['fish']) # Remove an element from a dictionary\n", "print(d.get('fish', 'N/A')) # \"fish\" is no longer a key; prints \"N/A\"" ] }, { "cell_type": "markdown", "id": "ae030323", "metadata": {}, "source": [ "It is easy to iterate over the keys in a dictionary:" ] }, { "cell_type": "code", "execution_count": null, "id": "23b63cbb", "metadata": {}, "outputs": [], "source": [ "d = {'person': 2, 'cat': 4, 'spider': 8}\n", "for animal in d:\n", " legs = d[animal]\n", " print('A', animal, 'has', legs, 'legs')" ] }, { "cell_type": "markdown", "id": "ef1448a4", "metadata": {}, "source": [ "If you want access to keys and their corresponding values, use the items method:" ] }, { "cell_type": "code", "execution_count": null, "id": "2e5ed33d", "metadata": {}, "outputs": [], "source": [ "d = {'person': 2, 'cat': 4, 'spider': 8}\n", "for animal, legs in d.items():\n", " print('A', animal, 'has', legs, 'legs')" ] }, { "cell_type": "markdown", "id": "1a9ecf0d", "metadata": {}, "source": [ "Dictionary comprehensions: These are similar to list comprehensions, but allow you to easily construct dictionaries. For example:" ] }, { "cell_type": "code", "execution_count": null, "id": "8a1e9ebe", "metadata": {}, "outputs": [], "source": [ "nums = [0, 1, 2, 3, 4]\n", "even_num_to_square = {x: x ** 2 for x in nums if x % 2 == 0}\n", "print(even_num_to_square)" ] }, { "cell_type": "markdown", "id": "eb411779", "metadata": {}, "source": [ "#### Sets" ] }, { "cell_type": "markdown", "id": "0315fa88", "metadata": {}, "source": [ "A set is an unordered collection of distinct elements. As a simple example, consider the following:" ] }, { "cell_type": "code", "execution_count": null, "id": "b9114c18", "metadata": {}, "outputs": [], "source": [ "animals = {'cat', 'dog'}\n", "print('cat' in animals) # Check if an element is in a set; prints \"True\"\n", "print('fish' in animals) # prints \"False\"" ] }, { "cell_type": "code", "execution_count": null, "id": "1f939a49", "metadata": {}, "outputs": [], "source": [ "animals.add('fish') # Add an element to a set\n", "print('fish' in animals)\n", "print(len(animals)) # Number of elements in a set;" ] }, { "cell_type": "code", "execution_count": null, "id": "f648df3f", "metadata": {}, "outputs": [], "source": [ "animals.add('cat') # Adding an element that is already in the set does nothing\n", "print(len(animals)) \n", "animals.remove('cat') # Remove an element from a set\n", "print(len(animals)) " ] }, { "cell_type": "markdown", "id": "24a47b06", "metadata": {}, "source": [ "_Loops_: Iterating over a set has the same syntax as iterating over a list; however since sets are unordered, you cannot make assumptions about the order in which you visit the elements of the set:" ] }, { "cell_type": "code", "execution_count": null, "id": "3d87e853", "metadata": {}, "outputs": [], "source": [ "animals = {'cat', 'dog', 'fish'}\n", "for idx, animal in enumerate(animals):\n", " print(idx + 1,':', animal)\n", "# Prints \"1 : fish\", \"2 : dog\", \"3 : cat\"" ] }, { "cell_type": "markdown", "id": "6a76dbbc", "metadata": {}, "source": [ "Set comprehensions: Like lists and dictionaries, we can easily construct sets using set comprehensions:" ] }, { "cell_type": "code", "execution_count": null, "id": "05e963e2", "metadata": {}, "outputs": [], "source": [ "from math import sqrt\n", "print({int(sqrt(x)) for x in range(30)})" ] }, { "cell_type": "markdown", "id": "48fced9b", "metadata": {}, "source": [ "#### Tuples" ] }, { "cell_type": "markdown", "id": "a40c5f6f", "metadata": {}, "source": [ "A tuple is an (immutable) ordered list of values. A tuple is in many ways similar to a list; one of the most important differences is that tuples can be used as keys in dictionaries and as elements of sets, while lists cannot. Here is a trivial example:" ] }, { "cell_type": "code", "execution_count": null, "id": "05bab749", "metadata": {}, "outputs": [], "source": [ "d = {(x, x + 1): x for x in range(10)} # Create a dictionary with tuple keys\n", "t = (5, 6) # Create a tuple\n", "print(type(t))\n", "print(d[t]) \n", "print(d[(1, 2)])" ] }, { "cell_type": "code", "execution_count": null, "id": "016e4334", "metadata": {}, "outputs": [], "source": [ "t[0] = 1" ] }, { "cell_type": "markdown", "id": "7e632983", "metadata": {}, "source": [ "### Functions" ] }, { "cell_type": "markdown", "id": "e5503add", "metadata": {}, "source": [ "Python functions are defined using the `def` keyword. For example:" ] }, { "cell_type": "code", "execution_count": null, "id": "445aa8c6", "metadata": {}, "outputs": [], "source": [ "def sign(x):\n", " if x > 0:\n", " return 'positive'\n", " elif x < 0:\n", " return 'negative'\n", " else:\n", " return 'zero'\n", "\n", "for x in [-1, 0, 1]:\n", " print(sign(x))" ] }, { "cell_type": "markdown", "id": "5c3c12b3", "metadata": {}, "source": [ "We will often define functions to take optional keyword arguments, like this:" ] }, { "cell_type": "code", "execution_count": null, "id": "1e1646f8", "metadata": {}, "outputs": [], "source": [ "def hello(name, loud=False):\n", " if loud:\n", " print('HELLO', name.upper())\n", " else:\n", " print('Hello', name)\n", "\n", "hello('Bob')\n", "hello('Fred', loud=True)" ] }, { "cell_type": "markdown", "id": "135435a8", "metadata": {}, "source": [ "## Numpy" ] }, { "cell_type": "markdown", "id": "7fb52db6", "metadata": {}, "source": [ "Numpy is the core library for scientific computing in Python. It provides a high-performance multidimensional array object, and tools for working with these arrays." ] }, { "cell_type": "markdown", "id": "8b84e326", "metadata": {}, "source": [ "To use Numpy, we first need to import the `numpy` package:" ] }, { "cell_type": "code", "execution_count": null, "id": "430dfc08", "metadata": {}, "outputs": [], "source": [ "import numpy as np" ] }, { "cell_type": "markdown", "id": "222b8ef8", "metadata": {}, "source": [ "### Arrays" ] }, { "cell_type": "markdown", "id": "325b608f", "metadata": {}, "source": [ "A numpy array is a grid of values, all of the same type, and is indexed by a tuple of nonnegative integers. The number of dimensions is the rank of the array; the shape of an array is a tuple of integers giving the size of the array along each dimension." ] }, { "cell_type": "markdown", "id": "1aed17eb", "metadata": {}, "source": [ "We can initialize numpy arrays from nested Python lists, and access elements using square brackets:" ] }, { "cell_type": "code", "execution_count": null, "id": "c3077a0f", "metadata": {}, "outputs": [], "source": [ "a = np.array([1, 2, 3]) # Create a rank 1 array\n", "print(type(a), a.shape, a[0], a[1], a[2])\n", "a[0] = 5 # Change an element of the array\n", "print(a) " ] }, { "cell_type": "code", "execution_count": null, "id": "962d122c", "metadata": {}, "outputs": [], "source": [ "b = np.array([[1,2,3],[4,5,6]]) # Create a rank 2 array\n", "print(b)" ] }, { "cell_type": "code", "execution_count": null, "id": "c339257e", "metadata": {}, "outputs": [], "source": [ "print(b.shape) \n", "print(b[0, 0], b[0, 1], b[1, 0])" ] }, { "cell_type": "markdown", "id": "12909900", "metadata": {}, "source": [ "Numpy also provides many functions to create arrays:" ] }, { "cell_type": "code", "execution_count": null, "id": "38333b55", "metadata": {}, "outputs": [], "source": [ "a = np.zeros((2,2)) # Create an array of all zeros\n", "print(a)" ] }, { "cell_type": "code", "execution_count": null, "id": "f333848e", "metadata": {}, "outputs": [], "source": [ "b = np.ones((1,2)) # Create an array of all ones\n", "print(b)" ] }, { "cell_type": "code", "execution_count": null, "id": "a9ba5cb7", "metadata": {}, "outputs": [], "source": [ "c = np.full((2,2), 7) # Create a constant array\n", "print(c) " ] }, { "cell_type": "code", "execution_count": null, "id": "6c02ab99", "metadata": {}, "outputs": [], "source": [ "d = np.eye(2) # Create a 2x2 identity matrix\n", "print(d)" ] }, { "cell_type": "code", "execution_count": null, "id": "3ad5a101", "metadata": {}, "outputs": [], "source": [ "e = np.random.random((2,2)) # Create an array filled with random values\n", "print(e)" ] }, { "cell_type": "markdown", "id": "8afb6ed8", "metadata": {}, "source": [ "### Array indexing" ] }, { "cell_type": "markdown", "id": "591adf59", "metadata": {}, "source": [ "Numpy offers several ways to index into arrays." ] }, { "cell_type": "markdown", "id": "36f88e9f", "metadata": {}, "source": [ "Slicing: Similar to Python lists, numpy arrays can be sliced. Since arrays may be multidimensional, you must specify a slice for each dimension of the array:" ] }, { "cell_type": "code", "execution_count": null, "id": "5924438a", "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "\n", "# Create the following rank 2 array with shape (3, 4)\n", "# [[ 1 2 3 4]\n", "# [ 5 6 7 8]\n", "# [ 9 10 11 12]]\n", "a = np.array([[1,2,3,4], [5,6,7,8], [9,10,11,12]])\n", "\n", "# Use slicing to pull out the subarray consisting of the first 2 rows\n", "# and columns 1 and 2; b is the following array of shape (2, 2):\n", "# [[2 3]\n", "# [6 7]]\n", "b = a[:2, 1:3]\n", "print(b)" ] }, { "cell_type": "markdown", "id": "b7bae057", "metadata": {}, "source": [ "A slice of an array is a view into the same data, so modifying it will modify the original array." ] }, { "cell_type": "code", "execution_count": null, "id": "9e3f1d28", "metadata": {}, "outputs": [], "source": [ "print(a[0, 1])\n", "b[0, 0] = 77 # b[0, 0] is the same piece of data as a[0, 1]\n", "print(a[0, 1]) " ] }, { "cell_type": "markdown", "id": "1cf9e2d2", "metadata": {}, "source": [ "You can also mix integer indexing with slice indexing. However, doing so will yield an array of lower rank than the original array. Note that this is quite different from the way that MATLAB handles array slicing:" ] }, { "cell_type": "code", "execution_count": null, "id": "1105e59d", "metadata": {}, "outputs": [], "source": [ "# Create the following rank 2 array with shape (3, 4)\n", "a = np.array([[1,2,3,4], [5,6,7,8], [9,10,11,12]])\n", "print(a)" ] }, { "cell_type": "markdown", "id": "2ed2418c", "metadata": {}, "source": [ "Two ways of accessing the data in the middle row of the array.\n", "Mixing integer indexing with slices yields an array of lower rank,\n", "while using only slices yields an array of the same rank as the\n", "original array:" ] }, { "cell_type": "code", "execution_count": null, "id": "7a706fb9", "metadata": {}, "outputs": [], "source": [ "row_r1 = a[1, :] # Rank 1 view of the second row of a \n", "row_r2 = a[1:2, :] # Rank 2 view of the second row of a\n", "row_r3 = a[[1], :] # Rank 2 view of the second row of a\n", "print(row_r1, row_r1.shape)\n", "print(row_r2, row_r2.shape)\n", "print(row_r3, row_r3.shape)" ] }, { "cell_type": "code", "execution_count": null, "id": "d12c1a69", "metadata": {}, "outputs": [], "source": [ "# We can make the same distinction when accessing columns of an array:\n", "col_r1 = a[:, 1]\n", "col_r2 = a[:, 1:2]\n", "print(col_r1, col_r1.shape)\n", "print(col_r2, col_r2.shape)" ] }, { "cell_type": "markdown", "id": "aca9b0e4", "metadata": {}, "source": [ "Integer array indexing: When you index into numpy arrays using slicing, the resulting array view will always be a subarray of the original array. In contrast, integer array indexing allows you to construct arbitrary arrays using the data from another array. Here is an example:" ] }, { "cell_type": "code", "execution_count": null, "id": "bbcd136a", "metadata": {}, "outputs": [], "source": [ "a = np.array([[1,2], [3, 4], [5, 6]])\n", "\n", "# An example of integer array indexing.\n", "# The returned array will have shape (3,) and \n", "print(a[[0, 1, 2], [0, 1, 0]])\n", "\n", "# The above example of integer array indexing is equivalent to this:\n", "print(np.array([a[0, 0], a[1, 1], a[2, 0]]))" ] }, { "cell_type": "code", "execution_count": null, "id": "dc1958ab", "metadata": {}, "outputs": [], "source": [ "# When using integer array indexing, you can reuse the same\n", "# element from the source array:\n", "print(a[[0, 0], [1, 1]])\n", "\n", "# Equivalent to the previous integer array indexing example\n", "print(np.array([a[0, 1], a[0, 1]]))" ] }, { "cell_type": "markdown", "id": "618ead88", "metadata": {}, "source": [ "One useful trick with integer array indexing is selecting or mutating one element from each row of a matrix:" ] }, { "cell_type": "code", "execution_count": null, "id": "75925559", "metadata": {}, "outputs": [], "source": [ "# Create a new array from which we will select elements\n", "a = np.array([[1,2,3], [4,5,6], [7,8,9], [10, 11, 12]])\n", "print(a)" ] }, { "cell_type": "code", "execution_count": null, "id": "d4116a43", "metadata": {}, "outputs": [], "source": [ "# Create an array of indices\n", "b = np.array([0, 2, 0, 1])\n", "\n", "# Select one element from each row of a using the indices in b\n", "print(a[np.arange(4), b]) # Prints \"[ 1 6 7 11]\"" ] }, { "cell_type": "code", "execution_count": null, "id": "8afac8a4", "metadata": {}, "outputs": [], "source": [ "# Mutate one element from each row of a using the indices in b\n", "a[np.arange(4), b] += 10\n", "print(a)" ] }, { "cell_type": "markdown", "id": "c29e259e", "metadata": {}, "source": [ "Boolean array indexing: Boolean array indexing lets you pick out arbitrary elements of an array. Frequently this type of indexing is used to select the elements of an array that satisfy some condition. Here is an example:" ] }, { "cell_type": "code", "execution_count": null, "id": "74547920", "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "\n", "a = np.array([[1,2], [3, 4], [5, 6]])\n", "\n", "bool_idx = (a > 2) # Find the elements of a that are bigger than 2;\n", " # this returns a numpy array of Booleans of the same\n", " # shape as a, where each slot of bool_idx tells\n", " # whether that element of a is > 2.\n", "\n", "print(bool_idx)" ] }, { "cell_type": "code", "execution_count": null, "id": "39d506a7", "metadata": {}, "outputs": [], "source": [ "# We use boolean array indexing to construct a rank 1 array\n", "# consisting of the elements of a corresponding to the True values\n", "# of bool_idx\n", "print(a[bool_idx])\n", "\n", "# We can do all of the above in a single concise statement:\n", "print(a[a > 2])" ] }, { "cell_type": "markdown", "id": "ca66d928", "metadata": {}, "source": [ "For brevity we have left out a lot of details about numpy array indexing; if you want to know more you should read the documentation." ] }, { "cell_type": "markdown", "id": "c830eb08", "metadata": {}, "source": [ "### Datatypes" ] }, { "cell_type": "markdown", "id": "3bc5772f", "metadata": {}, "source": [ "Every numpy array is a grid of elements of the same type. Numpy provides a large set of numeric datatypes that you can use to construct arrays. Numpy tries to guess a datatype when you create an array, but functions that construct arrays usually also include an optional argument to explicitly specify the datatype. Here is an example:" ] }, { "cell_type": "code", "execution_count": null, "id": "72319c05", "metadata": {}, "outputs": [], "source": [ "x = np.array([1, 2]) # Let numpy choose the datatype\n", "y = np.array([1.0, 2.0]) # Let numpy choose the datatype\n", "z = np.array([1, 2], dtype=np.int64) # Force a particular datatype\n", "\n", "print(x.dtype, y.dtype, z.dtype)" ] }, { "cell_type": "markdown", "id": "cefff45d", "metadata": {}, "source": [ "You can read all about numpy datatypes in the [documentation](http://docs.scipy.org/doc/numpy/reference/arrays.dtypes.html)." ] }, { "cell_type": "markdown", "id": "e19f5449", "metadata": {}, "source": [ "### Array math" ] }, { "cell_type": "markdown", "id": "6bbc165a", "metadata": {}, "source": [ "Basic mathematical functions operate elementwise on arrays, and are available both as operator overloads and as functions in the numpy module:" ] }, { "cell_type": "code", "execution_count": null, "id": "49563194", "metadata": {}, "outputs": [], "source": [ "x = np.array([[1,2],[3,4]], dtype=np.float64)\n", "y = np.array([[5,6],[7,8]], dtype=np.float64)\n", "\n", "# Elementwise sum; both produce the array\n", "print(x + y)\n", "print(np.add(x, y))" ] }, { "cell_type": "code", "execution_count": null, "id": "05a93949", "metadata": {}, "outputs": [], "source": [ "# Elementwise difference; both produce the array\n", "print(x - y)\n", "print(np.subtract(x, y))" ] }, { "cell_type": "code", "execution_count": null, "id": "fe12f6a4", "metadata": {}, "outputs": [], "source": [ "# Elementwise product; both produce the array\n", "print(x * y)\n", "print(np.multiply(x, y))" ] }, { "cell_type": "code", "execution_count": null, "id": "b6ca8683", "metadata": {}, "outputs": [], "source": [ "# Elementwise division; both produce the array\n", "# [[ 0.2 0.33333333]\n", "# [ 0.42857143 0.5 ]]\n", "print(x / y)\n", "print(np.divide(x, y))" ] }, { "cell_type": "code", "execution_count": null, "id": "9416c8b6", "metadata": {}, "outputs": [], "source": [ "# Elementwise square root; produces the array\n", "# [[ 1. 1.41421356]\n", "# [ 1.73205081 2. ]]\n", "print(np.sqrt(x))" ] }, { "cell_type": "markdown", "id": "6531db85", "metadata": {}, "source": [ "Note that unlike MATLAB, `*` is elementwise multiplication, not matrix multiplication. We instead use the dot function to compute inner products of vectors, to multiply a vector by a matrix, and to multiply matrices. dot or @ is available both as a function in the numpy module and as an instance method of array objects:" ] }, { "cell_type": "code", "execution_count": null, "id": "75fca179", "metadata": {}, "outputs": [], "source": [ "x = np.array([[1,2],[3,4]])\n", "y = np.array([[5,6],[7,8]])\n", "\n", "v = np.array([9,10])\n", "w = np.array([11, 12])\n", "\n", "# Inner product of vectors; both produce 219\n", "print(v.dot(w))\n", "print(v@w)\n", "print(np.dot(v, w))" ] }, { "cell_type": "code", "execution_count": null, "id": "0ce9871b", "metadata": {}, "outputs": [], "source": [ "# Matrix / vector product; both produce the rank 1 array [29 67]\n", "print(x.dot(v))\n", "print(np.dot(x, v))" ] }, { "cell_type": "code", "execution_count": null, "id": "8c03e7f8", "metadata": {}, "outputs": [], "source": [ "# Matrix / matrix product; both produce the rank 2 array\n", "# [[19 22]\n", "# [43 50]]\n", "print(x.dot(y))\n", "print(np.dot(x, y))" ] }, { "cell_type": "markdown", "id": "7880f8a6", "metadata": {}, "source": [ "Numpy provides many useful functions for performing computations on arrays; one of the most useful is `sum`:" ] }, { "cell_type": "code", "execution_count": null, "id": "83ea7378", "metadata": {}, "outputs": [], "source": [ "x = np.array([[1,2],[3,4]])\n", "\n", "print(np.sum(x)) # Compute sum of all elements; prints \"10\"\n", "print(np.sum(x, axis=0)) # Compute sum of each column; prints \"[4 6]\"\n", "print(np.sum(x, axis=1)) # Compute sum of each row; prints \"[3 7]\"" ] }, { "cell_type": "markdown", "id": "682d35ba", "metadata": {}, "source": [ "Apart from computing mathematical functions using arrays, we frequently need to reshape or otherwise manipulate data in arrays. The simplest example of this type of operation is transposing a matrix; to transpose a matrix, simply use the T attribute of an array object:" ] }, { "cell_type": "code", "execution_count": null, "id": "81fde83d", "metadata": {}, "outputs": [], "source": [ "print(x)\n", "print(x.T)" ] }, { "cell_type": "code", "execution_count": null, "id": "07a3b012", "metadata": {}, "outputs": [], "source": [ "v = np.array([[1,2,3]])\n", "print(v) \n", "print(v.T)" ] }, { "cell_type": "markdown", "id": "0ff8b1ef", "metadata": {}, "source": [ "### Broadcasting" ] }, { "cell_type": "markdown", "id": "fccbfa06", "metadata": {}, "source": [ "Broadcasting is a powerful mechanism that allows numpy to work with arrays of different shapes when performing arithmetic operations. Frequently we have a smaller array and a larger array, and we want to use the smaller array multiple times to perform some operation on the larger array.\n", "\n", "For example, suppose that we want to add a constant vector to each row of a matrix. We could do it like this:" ] }, { "cell_type": "code", "execution_count": null, "id": "34f61864", "metadata": {}, "outputs": [], "source": [ "# We will add the vector v to each row of the matrix x,\n", "# storing the result in the matrix y\n", "x = np.array([[1,2,3], [4,5,6], [7,8,9], [10, 11, 12]])\n", "v = np.array([1, 0, 1])\n", "y = np.empty_like(x) # Create an empty matrix with the same shape as x\n", "\n", "# Add the vector v to each row of the matrix x with an explicit loop\n", "for i in range(4):\n", " y[i, :] = x[i, :] + v\n", " \n", "print(y)\n" ] }, { "cell_type": "markdown", "id": "3bd1b4cc", "metadata": {}, "source": [ "This works; however when the matrix `x` is very large, computing an explicit loop in Python could be slow. Note that adding the vector v to each row of the matrix `x` is equivalent to forming a matrix `vv` by stacking multiple copies of `v` vertically, then performing elementwise summation of `x` and `vv`. We could implement this approach like this:" ] }, { "cell_type": "code", "execution_count": null, "id": "3e75d750", "metadata": {}, "outputs": [], "source": [ "vv = np.tile(v, (4, 1)) # Stack 4 copies of v on top of each other\n", "print(vv) # Prints \"[[1 0 1]\n", " # [1 0 1]\n", " # [1 0 1]\n", " # [1 0 1]]\"" ] }, { "cell_type": "code", "execution_count": null, "id": "9a83dabf", "metadata": {}, "outputs": [], "source": [ "y = x + vv # Add x and vv elementwise\n", "print(y)" ] }, { "cell_type": "markdown", "id": "f0adac8c", "metadata": {}, "source": [ "Numpy broadcasting allows us to perform this computation without actually creating multiple copies of v. Consider this version, using broadcasting:" ] }, { "cell_type": "code", "execution_count": null, "id": "1831049e", "metadata": {}, "outputs": [], "source": [ "# We will add the vector v to each row of the matrix x,\n", "# storing the result in the matrix y\n", "x = np.array([[1,2,3], [4,5,6], [7,8,9], [10, 11, 12]])\n", "v = np.array([1, 0, 1])\n", "y = x + v # Add v to each row of x using broadcasting\n", "print(y)\n" ] }, { "cell_type": "markdown", "id": "e225d4ca", "metadata": {}, "source": [ "The line `y = x + v` works even though `x` has shape `(4, 3)` and `v` has shape `(3,)` due to broadcasting; this line works as if v actually had shape `(4, 3)`, where each row was a copy of `v`, and the sum was performed elementwise.\n", "\n", "Broadcasting two arrays together follows these rules:\n", "\n", "1. If the arrays do not have the same rank, prepend the shape of the lower rank array with 1s until both shapes have the same length.\n", "2. The two arrays are said to be compatible in a dimension if they have the same size in the dimension, or if one of the arrays has size 1 in that dimension.\n", "3. The arrays can be broadcast together if they are compatible in all dimensions.\n", "4. After broadcasting, each array behaves as if it had shape equal to the elementwise maximum of shapes of the two input arrays.\n", "5. In any dimension where one array had size 1 and the other array had size greater than 1, the first array behaves as if it were copied along that dimension\n", "\n", "Here are some applications of broadcasting:" ] }, { "cell_type": "code", "execution_count": null, "id": "9406ec6d", "metadata": {}, "outputs": [], "source": [ "# Compute outer product of vectors\n", "v = np.array([1,2,3]) # v has shape (3,)\n", "w = np.array([4,5]) # w has shape (2,)\n", "# To compute an outer product, we first reshape v to be a column\n", "# vector of shape (3, 1); we can then broadcast it against w to yield\n", "# an output of shape (3, 2), which is the outer product of v and w:\n", "\n", "print(np.reshape(v, (3, 1)) * w)\n" ] }, { "cell_type": "code", "execution_count": null, "id": "9c19c779", "metadata": {}, "outputs": [], "source": [ "# Add a vector to each row of a matrix\n", "x = np.array([[1,2,3], [4,5,6]])\n", "# x has shape (2, 3) and v has shape (3,) so they broadcast to (2, 3),\n", "# giving the following matrix:\n", "\n", "print(x + v)\n" ] }, { "cell_type": "code", "execution_count": null, "id": "3d4e227c", "metadata": {}, "outputs": [], "source": [ "# Add a vector to each column of a matrix\n", "# x has shape (2, 3) and w has shape (2,).\n", "# If we transpose x then it has shape (3, 2) and can be broadcast\n", "# against w to yield a result of shape (3, 2); transposing this result\n", "# yields the final result of shape (2, 3) which is the matrix x with\n", "# the vector w added to each column. Gives the following matrix:\n", "\n", "print((x.T + w).T)\n" ] }, { "cell_type": "code", "execution_count": null, "id": "ecbcc253", "metadata": {}, "outputs": [], "source": [ "# Another solution is to reshape w to be a row vector of shape (2, 1);\n", "# we can then broadcast it directly against x to produce the same\n", "# output.\n", "\n", "print(x + np.reshape(w, (2, 1)))\n" ] }, { "cell_type": "code", "execution_count": null, "id": "41e23596", "metadata": {}, "outputs": [], "source": [ "# Multiply a matrix by a constant:\n", "# x has shape (2, 3). Numpy treats scalars as arrays of shape ();\n", "# these can be broadcast together to shape (2, 3), producing the\n", "# following array:\n", "\n", "print(x * 2)\n" ] }, { "cell_type": "markdown", "id": "57dd4ae8", "metadata": {}, "source": [ "Broadcasting typically makes your code more concise and faster, so you should strive to use it where possible." ] }, { "cell_type": "markdown", "id": "3d3a9308", "metadata": {}, "source": [ "## Matplotlib" ] }, { "cell_type": "markdown", "id": "040278b1", "metadata": {}, "source": [ "Matplotlib is a plotting library. In this section give a brief introduction to the `matplotlib.pyplot` module, which provides a plotting system similar to that of MATLAB." ] }, { "cell_type": "code", "execution_count": null, "id": "69225741", "metadata": {}, "outputs": [], "source": [ "import matplotlib.pyplot as plt\n" ] }, { "cell_type": "markdown", "id": "8a5af016", "metadata": {}, "source": [ "By running this special iPython command, we will be displaying plots inline:" ] }, { "cell_type": "code", "execution_count": null, "id": "ce1d5b83", "metadata": {}, "outputs": [], "source": [ "%matplotlib inline\n" ] }, { "cell_type": "markdown", "id": "636fa079", "metadata": {}, "source": [ "### Plotting" ] }, { "cell_type": "markdown", "id": "bb569abc", "metadata": {}, "source": [ "The most important function in `matplotlib` is plot, which allows you to plot 2D data. Here is a simple example:" ] }, { "cell_type": "code", "execution_count": null, "id": "01636a84", "metadata": {}, "outputs": [], "source": [ "# Compute the x and y coordinates for points on a sine curve\n", "x = np.arange(0, 3 * np.pi, 0.1)\n", "y = np.sin(x)\n", "\n", "# Plot the points using matplotlib\n", "plt.plot(x, y)\n", "plt.show()\n" ] }, { "cell_type": "markdown", "id": "9e03777e", "metadata": {}, "source": [ "With just a little bit of extra work we can easily plot multiple lines at once, and add a title, legend, and axis labels:" ] }, { "cell_type": "code", "execution_count": null, "id": "1fe30b1d", "metadata": {}, "outputs": [], "source": [ "y_sin = np.sin(x)\n", "y_cos = np.cos(x)\n", "\n", "# Plot the points using matplotlib\n", "plt.plot(x, y_sin)\n", "plt.plot(x, y_cos)\n", "plt.xlabel('x axis label')\n", "plt.ylabel('y axis label')\n", "plt.title('Sine and Cosine')\n", "plt.legend(['Sine', 'Cosine'])\n", "plt.show()\n" ] }, { "cell_type": "markdown", "id": "65bd91b1", "metadata": {}, "source": [ "### Subplots " ] }, { "cell_type": "markdown", "id": "69c17032", "metadata": {}, "source": [ "You can plot different things in the same figure using the subplot function. Here is an example:" ] }, { "cell_type": "code", "execution_count": null, "id": "59a280be", "metadata": {}, "outputs": [], "source": [ "# Compute the x and y coordinates for points on sine and cosine curves\n", "x = np.arange(0, 3 * np.pi, 0.1)\n", "y_sin = np.sin(x)\n", "y_cos = np.cos(x)\n", "\n", "# Set up a subplot grid that has height 2 and width 1,\n", "# and set the first such subplot as active.\n", "plt.subplot(2, 1, 1)\n", "\n", "# Make the first plot\n", "plt.plot(x, y_sin)\n", "plt.title('Sine')\n", "\n", "# Set the second subplot as active, and make the second plot.\n", "plt.subplot(2, 1, 2)\n", "plt.plot(x, y_cos)\n", "plt.title('Cosine')\n", "\n", "# Show the figure.\n", "plt.show()\n" ] } ], "metadata": { "anaconda-cloud": {}, "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.7.6" }, "unianalytics_cell_mapping": [ [ "282fb346", "282fb346" ], [ "9c4b8d73", "9c4b8d73" ], [ "7e800b7a", "7e800b7a" ], [ "24365782", "24365782" ], [ "5b2a3e29", "5b2a3e29" ], [ "790b8467", "790b8467" ], [ "daf262e0", "daf262e0" ], [ "cafdbb77", "cafdbb77" ], [ "dc1d1855", "dc1d1855" ], [ "dc8282ec", "dc8282ec" ], [ "aaf39b03", "aaf39b03" ], [ "5f0b01d6", "5f0b01d6" ], [ "8976830d", "8976830d" ], [ "ba77d9db", "ba77d9db" ], [ "3ea3c5a6", "3ea3c5a6" ], [ "84a3ca7a", "84a3ca7a" ], [ "ff70d562", "ff70d562" ], [ "09add47f", "09add47f" ], [ "80a99d03", "80a99d03" ], [ "350d890e", "350d890e" ], [ "5377ecb6", "5377ecb6" ], [ "e6ccf5c6", "e6ccf5c6" ], [ "f087114e", "f087114e" ], [ "576795d2", "576795d2" ], [ "cfca718d", "cfca718d" ], [ "6f692aa4", "6f692aa4" ], [ "07f33c25", "07f33c25" ], [ "00f8d6a4", "00f8d6a4" ], [ "3dfc4c01", "3dfc4c01" ], [ "667b1dcc", "667b1dcc" ], [ "2a1b72ee", "2a1b72ee" ], [ "fb1053b0", "fb1053b0" ], [ "6b8ee616", "6b8ee616" ], [ "de584920", "de584920" ], [ "2477623b", "2477623b" ], [ "dab4ccd0", "dab4ccd0" ], [ "0044e9a7", "0044e9a7" ], [ "22c25a60", "22c25a60" ], [ "50333650", "50333650" ], [ "94c9e50f", "94c9e50f" ], [ "4da38874", "4da38874" ], [ "95812c1e", "95812c1e" ], [ "965c7ecf", "965c7ecf" ], [ "35696e58", "35696e58" ], [ "cc6355fb", "cc6355fb" ], [ "a58bc6a5", "a58bc6a5" ], [ "7230e38a", "7230e38a" ], [ "2cd831d3", "2cd831d3" ], [ "f2d3792c", "f2d3792c" ], [ "98a3e39a", "98a3e39a" ], [ "30a8f579", "30a8f579" ], [ "2d6b876a", "2d6b876a" ], [ "48da43d3", "48da43d3" ], [ "1b6f55bc", "1b6f55bc" ], [ "d3ce77b0", "d3ce77b0" ], [ "9b8d50c2", "9b8d50c2" ], [ "66051c12", "66051c12" ], [ "8f4e1e93", "8f4e1e93" ], [ "6ea7eae1", "6ea7eae1" ], [ "ae030323", "ae030323" ], [ "23b63cbb", "23b63cbb" ], [ "ef1448a4", "ef1448a4" ], [ "2e5ed33d", "2e5ed33d" ], [ "1a9ecf0d", "1a9ecf0d" ], [ "8a1e9ebe", "8a1e9ebe" ], [ "eb411779", "eb411779" ], [ "0315fa88", "0315fa88" ], [ "b9114c18", "b9114c18" ], [ "1f939a49", "1f939a49" ], [ "f648df3f", "f648df3f" ], [ "24a47b06", "24a47b06" ], [ "3d87e853", "3d87e853" ], [ "6a76dbbc", "6a76dbbc" ], [ "05e963e2", "05e963e2" ], [ "48fced9b", "48fced9b" ], [ "a40c5f6f", "a40c5f6f" ], [ "05bab749", "05bab749" ], [ "016e4334", "016e4334" ], [ "7e632983", "7e632983" ], [ "e5503add", "e5503add" ], [ "445aa8c6", "445aa8c6" ], [ "5c3c12b3", "5c3c12b3" ], [ "1e1646f8", "1e1646f8" ], [ "135435a8", "135435a8" ], [ "7fb52db6", "7fb52db6" ], [ "8b84e326", "8b84e326" ], [ "430dfc08", "430dfc08" ], [ "222b8ef8", "222b8ef8" ], [ "325b608f", "325b608f" ], [ "1aed17eb", "1aed17eb" ], [ "c3077a0f", "c3077a0f" ], [ "962d122c", "962d122c" ], [ "c339257e", "c339257e" ], [ "12909900", "12909900" ], [ "38333b55", "38333b55" ], [ "f333848e", "f333848e" ], [ "a9ba5cb7", "a9ba5cb7" ], [ "6c02ab99", "6c02ab99" ], [ "3ad5a101", "3ad5a101" ], [ "8afb6ed8", "8afb6ed8" ], [ "591adf59", "591adf59" ], [ "36f88e9f", "36f88e9f" ], [ "5924438a", "5924438a" ], [ "b7bae057", "b7bae057" ], [ "9e3f1d28", "9e3f1d28" ], [ "1cf9e2d2", "1cf9e2d2" ], [ "1105e59d", "1105e59d" ], [ "2ed2418c", "2ed2418c" ], [ "7a706fb9", "7a706fb9" ], [ "d12c1a69", "d12c1a69" ], [ "aca9b0e4", "aca9b0e4" ], [ "bbcd136a", "bbcd136a" ], [ "dc1958ab", "dc1958ab" ], [ "618ead88", "618ead88" ], [ "75925559", "75925559" ], [ "d4116a43", "d4116a43" ], [ "8afac8a4", "8afac8a4" ], [ "c29e259e", "c29e259e" ], [ "74547920", "74547920" ], [ "39d506a7", "39d506a7" ], [ "ca66d928", "ca66d928" ], [ "c830eb08", "c830eb08" ], [ "3bc5772f", "3bc5772f" ], [ "72319c05", "72319c05" ], [ "cefff45d", "cefff45d" ], [ "e19f5449", "e19f5449" ], [ "6bbc165a", "6bbc165a" ], [ "49563194", "49563194" ], [ "05a93949", "05a93949" ], [ "fe12f6a4", "fe12f6a4" ], [ "b6ca8683", "b6ca8683" ], [ "9416c8b6", "9416c8b6" ], [ "6531db85", "6531db85" ], [ "75fca179", "75fca179" ], [ "0ce9871b", "0ce9871b" ], [ "8c03e7f8", "8c03e7f8" ], [ "7880f8a6", "7880f8a6" ], [ "83ea7378", "83ea7378" ], [ "682d35ba", "682d35ba" ], [ "81fde83d", "81fde83d" ], [ "07a3b012", "07a3b012" ], [ "0ff8b1ef", "0ff8b1ef" ], [ "fccbfa06", "fccbfa06" ], [ "34f61864", "34f61864" ], [ "3bd1b4cc", "3bd1b4cc" ], [ "3e75d750", "3e75d750" ], [ "9a83dabf", "9a83dabf" ], [ "f0adac8c", "f0adac8c" ], [ "1831049e", "1831049e" ], [ "e225d4ca", "e225d4ca" ], [ "9406ec6d", "9406ec6d" ], [ "9c19c779", "9c19c779" ], [ "3d4e227c", "3d4e227c" ], [ "ecbcc253", "ecbcc253" ], [ "41e23596", "41e23596" ], [ "57dd4ae8", "57dd4ae8" ], [ "3d3a9308", "3d3a9308" ], [ "040278b1", "040278b1" ], [ "69225741", "69225741" ], [ "8a5af016", "8a5af016" ], [ "ce1d5b83", "ce1d5b83" ], [ "636fa079", "636fa079" ], [ "bb569abc", "bb569abc" ], [ "01636a84", "01636a84" ], [ "9e03777e", "9e03777e" ], [ "1fe30b1d", "1fe30b1d" ], [ "65bd91b1", "65bd91b1" ], [ "69c17032", "69c17032" ], [ "59a280be", "59a280be" ] ], "unianalytics_notebook_id": "6134eb47-3a43-41e9-9b69-0be045c540cc" }, "nbformat": 4, "nbformat_minor": 5 }