├── .gitignore ├── README.md └── tutorials ├── assets └── cat.jpg ├── environments └── environment.yml └── python ├── cornell-cs5785-python-tutorial.ipynb ├── cs228-python-tutorial-3_7.ipynb └── cs228-python-tutorial.ipynb /.gitignore: -------------------------------------------------------------------------------- 1 | # latex stuff 2 | *.aux 3 | *.synctex.gz 4 | *.pdf 5 | 6 | # ipython stuff 7 | */.ipynb_checkpoints/* 8 | 9 | # Byte-compiled / optimized / DLL files 10 | __pycache__/ 11 | *.py[cod] 12 | 13 | # C extensions 14 | *.so 15 | 16 | # Distribution / packaging 17 | .Python 18 | env/ 19 | build/ 20 | develop-eggs/ 21 | dist/ 22 | downloads/ 23 | eggs/ 24 | .eggs/ 25 | lib/ 26 | lib64/ 27 | parts/ 28 | sdist/ 29 | var/ 30 | *.egg-info/ 31 | .installed.cfg 32 | *.egg 33 | 34 | # PyInstaller 35 | # Usually these files are written by a python script from a template 36 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 37 | *.manifest 38 | *.spec 39 | 40 | # Installer logs 41 | pip-log.txt 42 | pip-delete-this-directory.txt 43 | 44 | # Unit test / coverage reports 45 | htmlcov/ 46 | .tox/ 47 | .coverage 48 | .coverage.* 49 | .cache 50 | nosetests.xml 51 | coverage.xml 52 | *,cover 53 | 54 | # Translations 55 | *.mo 56 | *.pot 57 | 58 | # Django stuff: 59 | *.log 60 | 61 | # Sphinx documentation 62 | docs/_build/ 63 | 64 | # PyBuilder 65 | target/ 66 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Tutorials for Machine Learning Courses at Stanford and Cornell 2 | 3 | Preparatory material for machine learning courses at Stanford at Cornell. Covers Python and Numpy. This has been used for: 4 | * The probabilistic graphical models and the deep learning courses at Stanford. 5 | * The applied machine learning course and deep generative models courses at Cornell. 6 | 7 | ## Material 8 | 9 | This repo currently holds: 10 | 11 | * A [tutorial](https://github.com/kuleshov/cs228-material/blob/master/tutorials/python/cs228-python-tutorial.ipynb) on basic Python/Numpy that is necesseary to get started with the above machine learning classes. 12 | 13 | You may follow the iPython notebook on github, or clone and execute it locally. 14 | The notebook is based on an [earlier version](http://cs231n.github.io/python-numpy-tutorial/) prepared by Justin Johnson. 15 | -------------------------------------------------------------------------------- /tutorials/assets/cat.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kuleshov/teaching-material/5b8b3a7cdfc6474a00af45fa96133b3928f11de7/tutorials/assets/cat.jpg -------------------------------------------------------------------------------- /tutorials/environments/environment.yml: -------------------------------------------------------------------------------- 1 | name: np_tutorial_pv3 2 | 3 | dependencies: 4 | - python=3.7 5 | - jupyter 6 | - matplotlib 7 | - ipywidgets 8 | - numpy 9 | - scipy 10 | - imageio 11 | - scikit-image 12 | -------------------------------------------------------------------------------- /tutorials/python/cornell-cs5785-python-tutorial.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "**Applied Machine Learning Python Tutorial**
\n", 8 | "
\n", 9 | "Jupyter notebook by Volodymyr Kuleshov, Isaac Caswell, Shachi Deshpande, Alexandre St-Pierre-See based on the [CS231n Python v3.0 tutorial](http://cs231n.github.io/python-numpy-tutorial/) by Justin Johnson." 10 | ] 11 | }, 12 | { 13 | "cell_type": "markdown", 14 | "metadata": {}, 15 | "source": [ 16 | "# Introduction\n", 17 | "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", 18 | "\n", 19 | "We expect that many of you will have some experience with Python and numpy; for the rest of you, 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", 20 | "\n", 21 | "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/user/numpy-for-matlab-users.html)." 22 | ] 23 | }, 24 | { 25 | "cell_type": "markdown", 26 | "metadata": {}, 27 | "source": [ 28 | "In this tutorial, we will cover:\n", 29 | "\n", 30 | "* [Python](#python)\n", 31 | " * [Basic data types](#python-basic)\n", 32 | " * [Containers](#python-containers)\n", 33 | " * [Lists](#python-lists)\n", 34 | " * [Dictionaries](#python-dicts)\n", 35 | " * [Sets](#python-sets)\n", 36 | " * [Tuples](#python-tuples)\n", 37 | " * [Functions](#python-functions)\n", 38 | " * [Classes](#python-classes)\n", 39 | "* [Numpy](#numpy)\n", 40 | " * [Arrays](#numpy-arrays)\n", 41 | " * [Array indexing](#numpy-array-indexing)\n", 42 | " * [Datatypes](#numpy-datatypes)\n", 43 | " * [Array math](#numpy-array-math)\n", 44 | " * [Broadcasting](#numpy-broadcasting)\n", 45 | "* [SciPy](#scipy)\n", 46 | " * [Image operations](#scipy-image-operations)\n", 47 | " * [MATLAB files](#scipy-matlab)\n", 48 | " * [Distance between points](#scipy-distance)\n", 49 | "* [Matplotlib](#mpl)\n", 50 | " * [Plotting](#mpl-plot)\n", 51 | " * [Subplots](#mpl-subplot)\n", 52 | " * [Images](#mpl-images)" 53 | ] 54 | }, 55 | { 56 | "cell_type": "markdown", 57 | "metadata": {}, 58 | "source": [ 59 | "# Python\n", 60 | "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:" 61 | ] 62 | }, 63 | { 64 | "cell_type": "code", 65 | "execution_count": null, 66 | "metadata": {}, 67 | "outputs": [], 68 | "source": [ 69 | "def quicksort(arr):\n", 70 | " if len(arr) <= 1:\n", 71 | " return arr\n", 72 | " pivot = arr[len(arr) // 2]\n", 73 | " left = [x for x in arr if x < pivot]\n", 74 | " middle = [x for x in arr if x == pivot]\n", 75 | " right = [x for x in arr if x > pivot]\n", 76 | " return quicksort(left) + middle + quicksort(right)\n", 77 | "\n", 78 | "print(quicksort([3,6,8,10,1,2,1]))" 79 | ] 80 | }, 81 | { 82 | "cell_type": "markdown", 83 | "metadata": {}, 84 | "source": [ 85 | "### Python versions\n", 86 | "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. The latest Python version is 3.8.5 currently.\n", 87 | "\n", 88 | "You can check your Python version at the command line by running `python --version`." 89 | ] 90 | }, 91 | { 92 | "cell_type": "markdown", 93 | "metadata": {}, 94 | "source": [ 95 | "## Basic data types\n", 96 | "Like most languages, Python has a number of basic types including integers, floats, booleans, and strings. These data types behave in ways that are familiar from other programming languages.\n", 97 | "\n", 98 | "**Numbers**: Integers and floats work as you would expect from other languages:" 99 | ] 100 | }, 101 | { 102 | "cell_type": "code", 103 | "execution_count": null, 104 | "metadata": {}, 105 | "outputs": [], 106 | "source": [ 107 | "x = 3\n", 108 | "print(type(x)) # Prints \"\"" 109 | ] 110 | }, 111 | { 112 | "cell_type": "code", 113 | "execution_count": null, 114 | "metadata": {}, 115 | "outputs": [], 116 | "source": [ 117 | "print(x)\n", 118 | "print(x + 1) # Addition;\n", 119 | "print(x - 1) # Subtraction;\n", 120 | "print(x * 2) # Multiplication;\n", 121 | "print(x ** 2) # Exponentiation;" 122 | ] 123 | }, 124 | { 125 | "cell_type": "code", 126 | "execution_count": null, 127 | "metadata": {}, 128 | "outputs": [], 129 | "source": [ 130 | "print(x)\n", 131 | "x += 1\n", 132 | "print(x)" 133 | ] 134 | }, 135 | { 136 | "cell_type": "code", 137 | "execution_count": null, 138 | "metadata": {}, 139 | "outputs": [], 140 | "source": [ 141 | "x *= 2\n", 142 | "print(x)" 143 | ] 144 | }, 145 | { 146 | "cell_type": "code", 147 | "execution_count": null, 148 | "metadata": {}, 149 | "outputs": [], 150 | "source": [ 151 | "y = 2.5\n", 152 | "print(type(y)) # Prints \"\"\n", 153 | "print(y, y + 1, y * 2, y ** 2) # Prints \"2.5 3.5 5.0 6.25\"" 154 | ] 155 | }, 156 | { 157 | "cell_type": "markdown", 158 | "metadata": {}, 159 | "source": [ 160 | "Note that unlike many languages, Python does not have unary increment (`x++`) or decrement (`x--`) operators.\n", 161 | "\n", 162 | "Python also has built-in types for complex numbers; you can find all of the details [in the documentation](https://docs.python.org/3.7/library/stdtypes.html#numeric-types-int-float-complex)." 163 | ] 164 | }, 165 | { 166 | "cell_type": "markdown", 167 | "metadata": {}, 168 | "source": [ 169 | "**Booleans**: Python implements all of the usual operators for Boolean logic, but uses English words rather than symbols (`&&`, `||`, etc.):" 170 | ] 171 | }, 172 | { 173 | "cell_type": "code", 174 | "execution_count": null, 175 | "metadata": {}, 176 | "outputs": [], 177 | "source": [ 178 | "t = True\n", 179 | "f = False\n", 180 | "print(type(t)) # Prints \"\"\n" 181 | ] 182 | }, 183 | { 184 | "cell_type": "code", 185 | "execution_count": null, 186 | "metadata": {}, 187 | "outputs": [], 188 | "source": [ 189 | "print(t and f) # Logical AND; prints \"False\"\n", 190 | "print(t or f) # Logical OR; prints \"True\"\n", 191 | "print(not t) # Logical NOT; prints \"False\"\n", 192 | "print(t != f) # Logical XOR; prints \"True\"" 193 | ] 194 | }, 195 | { 196 | "cell_type": "markdown", 197 | "metadata": {}, 198 | "source": [ 199 | "**Strings**: Python has great support for strings:" 200 | ] 201 | }, 202 | { 203 | "cell_type": "code", 204 | "execution_count": null, 205 | "metadata": {}, 206 | "outputs": [], 207 | "source": [ 208 | "hello = 'hello' # String literals can use single quotes\n", 209 | "world = \"world\" # or double quotes; it does not matter.\n", 210 | "print(hello) # Prints \"hello\"\n", 211 | "print(len(hello)) # String length; prints \"5\"" 212 | ] 213 | }, 214 | { 215 | "cell_type": "code", 216 | "execution_count": null, 217 | "metadata": {}, 218 | "outputs": [], 219 | "source": [ 220 | "hw = hello + ' ' + world # String concatenation\n", 221 | "print(hw) # prints \"hello world\"" 222 | ] 223 | }, 224 | { 225 | "cell_type": "code", 226 | "execution_count": null, 227 | "metadata": {}, 228 | "outputs": [], 229 | "source": [ 230 | "hw12 = '%s %s %d' % (hello, world, 12) # sprintf style string formatting\n", 231 | "print(hw12) # prints \"hello world 12\"" 232 | ] 233 | }, 234 | { 235 | "cell_type": "markdown", 236 | "metadata": {}, 237 | "source": [ 238 | "String objects have a bunch of useful methods; for example:" 239 | ] 240 | }, 241 | { 242 | "cell_type": "code", 243 | "execution_count": null, 244 | "metadata": {}, 245 | "outputs": [], 246 | "source": [ 247 | "s = \"hello\"\n", 248 | "print(s.capitalize()) # Capitalize a string; prints \"Hello\"\n", 249 | "print(s.upper()) # Convert a string to uppercase; prints \"HELLO\"\n", 250 | "print(s.rjust(7)) # Right-justify a string, padding with spaces; prints \" hello\"\n", 251 | "print(s.center(7)) # Center a string, padding with spaces; prints \" hello \"" 252 | ] 253 | }, 254 | { 255 | "cell_type": "code", 256 | "execution_count": null, 257 | "metadata": {}, 258 | "outputs": [], 259 | "source": [ 260 | "print(s.replace('l', '(ell)')) # Replace all instances of one substring with another;\n", 261 | " # prints \"he(ell)(ell)o\"" 262 | ] 263 | }, 264 | { 265 | "cell_type": "code", 266 | "execution_count": null, 267 | "metadata": {}, 268 | "outputs": [], 269 | "source": [ 270 | "print(' world '.strip()) # Strip leading and trailing whitespace; prints \"world\"" 271 | ] 272 | }, 273 | { 274 | "cell_type": "markdown", 275 | "metadata": {}, 276 | "source": [ 277 | "You can find a list of all string methods [in the documentation](https://docs.python.org/3.7/library/stdtypes.html#string-methods)." 278 | ] 279 | }, 280 | { 281 | "cell_type": "markdown", 282 | "metadata": {}, 283 | "source": [ 284 | "## Containers\n", 285 | "Python includes several built-in container types: lists, dictionaries, sets, and tuples." 286 | ] 287 | }, 288 | { 289 | "cell_type": "markdown", 290 | "metadata": {}, 291 | "source": [ 292 | "### Lists\n", 293 | "A list is the Python equivalent of an array, but is resizeable and can contain elements of different types:" 294 | ] 295 | }, 296 | { 297 | "cell_type": "code", 298 | "execution_count": null, 299 | "metadata": { 300 | "scrolled": true 301 | }, 302 | "outputs": [], 303 | "source": [ 304 | "xs = [3, 1, 2] # Create a list\n", 305 | "print(xs, xs[2]) # Prints \"[3, 1, 2] 2\"\n", 306 | "print(xs[-2]) # Negative indices count from the end of the list; prints \"2\"" 307 | ] 308 | }, 309 | { 310 | "cell_type": "code", 311 | "execution_count": null, 312 | "metadata": {}, 313 | "outputs": [], 314 | "source": [ 315 | "xs[2] = 'foo' # Lists can contain elements of different types\n", 316 | "print(xs) # Prints \"[3, 1, 'foo']\"" 317 | ] 318 | }, 319 | { 320 | "cell_type": "code", 321 | "execution_count": null, 322 | "metadata": {}, 323 | "outputs": [], 324 | "source": [ 325 | "xs.append('bar') # Add a new element to the end of the list\n", 326 | "print(xs) # Prints \"[3, 1, 'foo', 'bar']\"" 327 | ] 328 | }, 329 | { 330 | "cell_type": "code", 331 | "execution_count": null, 332 | "metadata": { 333 | "scrolled": true 334 | }, 335 | "outputs": [], 336 | "source": [ 337 | "x = xs.pop() # Remove and return the last element of the list\n", 338 | "print(x, xs) # Prints \"bar [3, 1, 'foo']\"" 339 | ] 340 | }, 341 | { 342 | "cell_type": "code", 343 | "execution_count": null, 344 | "metadata": {}, 345 | "outputs": [], 346 | "source": [ 347 | "xs.pop(1) # remove element from a specific position\n", 348 | "print(xs)" 349 | ] 350 | }, 351 | { 352 | "cell_type": "markdown", 353 | "metadata": {}, 354 | "source": [ 355 | "As usual, you can find all the gory details about lists [in the documentation](https://docs.python.org/3.7/tutorial/datastructures.html#more-on-lists)." 356 | ] 357 | }, 358 | { 359 | "cell_type": "markdown", 360 | "metadata": {}, 361 | "source": [ 362 | "**Slicing**: In addition to accessing list elements one at a time, Python provides concise syntax to access sublists; this is known as slicing:" 363 | ] 364 | }, 365 | { 366 | "cell_type": "code", 367 | "execution_count": null, 368 | "metadata": {}, 369 | "outputs": [], 370 | "source": [ 371 | "nums = list(range(5)) # range is a built-in function that creates a list of integers\n", 372 | "print(nums) # Prints \"[0, 1, 2, 3, 4]\"\n", 373 | "print(nums[2:4]) # Get a slice from index 2 to 4 (exclusive); prints \"[2, 3]\"\n", 374 | "print(nums[2:]) # Get a slice from index 2 to the end; prints \"[2, 3, 4]\"\n", 375 | "print(nums[:2]) # Get a slice from the start to index 2 (exclusive); prints \"[0, 1]\"\n", 376 | "print(nums[:]) # Get a slice of the whole list; prints \"[0, 1, 2, 3, 4]\"\n", 377 | "print(nums[:-1]) # Slice indices can be negative; prints \"[0, 1, 2, 3]\"" 378 | ] 379 | }, 380 | { 381 | "cell_type": "code", 382 | "execution_count": null, 383 | "metadata": {}, 384 | "outputs": [], 385 | "source": [ 386 | "nums[2:4] = [8, 9] # Assign a new sublist to a slice\n", 387 | "print(nums) # Prints \"[0, 1, 8, 9, 4]\"" 388 | ] 389 | }, 390 | { 391 | "cell_type": "markdown", 392 | "metadata": {}, 393 | "source": [ 394 | "We will see slicing again in the context of numpy arrays." 395 | ] 396 | }, 397 | { 398 | "cell_type": "markdown", 399 | "metadata": {}, 400 | "source": [ 401 | "**Loops**: You can loop over the elements of a list like this:" 402 | ] 403 | }, 404 | { 405 | "cell_type": "code", 406 | "execution_count": null, 407 | "metadata": {}, 408 | "outputs": [], 409 | "source": [ 410 | "animals = ['cat', 'dog', 'monkey']\n", 411 | "for animal in animals:\n", 412 | " print(animal)\n", 413 | "# Prints \"cat\", \"dog\", \"monkey\", each on its own line." 414 | ] 415 | }, 416 | { 417 | "cell_type": "markdown", 418 | "metadata": {}, 419 | "source": [ 420 | "If you want access to the index of each element within the body of a loop, use the built-in `enumerate` function:" 421 | ] 422 | }, 423 | { 424 | "cell_type": "code", 425 | "execution_count": null, 426 | "metadata": {}, 427 | "outputs": [], 428 | "source": [ 429 | "animals = ['cat', 'dog', 'monkey']\n", 430 | "for idx, animal in enumerate(animals):\n", 431 | " print('#%d: %s' % (idx + 1, animal))\n", 432 | "# Prints \"#1: cat\", \"#2: dog\", \"#3: monkey\", each on its own line" 433 | ] 434 | }, 435 | { 436 | "cell_type": "markdown", 437 | "metadata": {}, 438 | "source": [ 439 | "**List comprehensions**: 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:" 440 | ] 441 | }, 442 | { 443 | "cell_type": "code", 444 | "execution_count": null, 445 | "metadata": {}, 446 | "outputs": [], 447 | "source": [ 448 | "nums = [0, 1, 2, 3, 4]\n", 449 | "squares = []\n", 450 | "for x in nums:\n", 451 | " squares.append(x ** 2)\n", 452 | "print(squares) # Prints [0, 1, 4, 9, 16]" 453 | ] 454 | }, 455 | { 456 | "cell_type": "markdown", 457 | "metadata": {}, 458 | "source": [ 459 | "You can make this code simpler using a **list comprehension**:" 460 | ] 461 | }, 462 | { 463 | "cell_type": "code", 464 | "execution_count": null, 465 | "metadata": {}, 466 | "outputs": [], 467 | "source": [ 468 | "nums = [0, 1, 2, 3, 4]\n", 469 | "squares = [x ** 2 for x in nums]\n", 470 | "print(squares) # Prints [0, 1, 4, 9, 16]" 471 | ] 472 | }, 473 | { 474 | "cell_type": "markdown", 475 | "metadata": {}, 476 | "source": [ 477 | "List comprehensions can also contain conditions:" 478 | ] 479 | }, 480 | { 481 | "cell_type": "code", 482 | "execution_count": null, 483 | "metadata": {}, 484 | "outputs": [], 485 | "source": [ 486 | "nums = [0, 1, 2, 3, 4]\n", 487 | "even_squares = [x ** 2 for x in nums if x % 2 == 1]\n", 488 | "print(even_squares) # Prints \"[0, 4, 16]\"" 489 | ] 490 | }, 491 | { 492 | "cell_type": "markdown", 493 | "metadata": {}, 494 | "source": [ 495 | "### Dictionaries\n", 496 | "A dictionary stores (key, value) pairs, similar to a `Map` in Java or an object in Javascript. You can use it like this:" 497 | ] 498 | }, 499 | { 500 | "cell_type": "code", 501 | "execution_count": null, 502 | "metadata": {}, 503 | "outputs": [], 504 | "source": [ 505 | "d = {'cat': 'cute', 'dog': 'furry'} # Create a new dictionary with some data\n", 506 | "print(d['cat']) # Get an entry from a dictionary; prints \"cute\"\n", 507 | "print('cat' in d) # Check if a dictionary has a given key; prints \"True\"" 508 | ] 509 | }, 510 | { 511 | "cell_type": "code", 512 | "execution_count": null, 513 | "metadata": {}, 514 | "outputs": [], 515 | "source": [ 516 | "d['fish'] = 'wet' # Set an entry in a dictionary\n", 517 | "print(d['fish']) # Prints \"wet\"\n", 518 | "#print(d['monkey']) # KeyError: 'monkey'" 519 | ] 520 | }, 521 | { 522 | "cell_type": "code", 523 | "execution_count": null, 524 | "metadata": {}, 525 | "outputs": [], 526 | "source": [ 527 | "print(d.get('monkey', 'N/A')) # Get an element with a default; prints \"N/A\"\n", 528 | "print(d.get('fish', 'N/A')) # Get an element with a default; prints \"wet\"\n", 529 | "del d['fish'] # Remove an element from a dictionary\n", 530 | "print(d.get('fish', 'N/A')) # \"fish\" is no longer a key; prints \"N/A\"" 531 | ] 532 | }, 533 | { 534 | "cell_type": "markdown", 535 | "metadata": {}, 536 | "source": [ 537 | "You can find all you need to know about dictionaries [in the documentation](https://docs.python.org/3.7/library/stdtypes.html#dict)." 538 | ] 539 | }, 540 | { 541 | "cell_type": "markdown", 542 | "metadata": {}, 543 | "source": [ 544 | "**Loops**: It is easy to iterate over the keys in a dictionary:" 545 | ] 546 | }, 547 | { 548 | "cell_type": "code", 549 | "execution_count": null, 550 | "metadata": {}, 551 | "outputs": [], 552 | "source": [ 553 | "d = {'person': 2, 'cat': 4, 'spider': 8}\n", 554 | "for animal, legs in d.items():\n", 555 | " #legs = d[animal]\n", 556 | " print('A %s has %d legs' % (animal, legs))\n", 557 | "# Prints \"A person has 2 legs\", \"A cat has 4 legs\", \"A spider has 8 legs\"" 558 | ] 559 | }, 560 | { 561 | "cell_type": "markdown", 562 | "metadata": {}, 563 | "source": [ 564 | "**Dictionary comprehensions**: These are similar to list comprehensions, but allow you to easily construct dictionaries. For example:" 565 | ] 566 | }, 567 | { 568 | "cell_type": "code", 569 | "execution_count": null, 570 | "metadata": {}, 571 | "outputs": [], 572 | "source": [ 573 | "nums = [0, 1, 2, 3, 4]\n", 574 | "even_num_to_square = {x: x ** 2 for x in nums if x % 2 == 0}\n", 575 | "print(even_num_to_square) # Prints \"{0: 0, 2: 4, 4: 16}\"" 576 | ] 577 | }, 578 | { 579 | "cell_type": "code", 580 | "execution_count": null, 581 | "metadata": {}, 582 | "outputs": [], 583 | "source": [ 584 | "another_dict = {x:x**3 for x in even_num_to_square}\n", 585 | "print(another_dict)" 586 | ] 587 | }, 588 | { 589 | "cell_type": "markdown", 590 | "metadata": {}, 591 | "source": [ 592 | "### Sets\n", 593 | "A set is an unordered collection of distinct elements. As a simple example, consider the following:" 594 | ] 595 | }, 596 | { 597 | "cell_type": "code", 598 | "execution_count": null, 599 | "metadata": {}, 600 | "outputs": [], 601 | "source": [ 602 | "animals = {'cat', 'dog'}\n", 603 | "print('cat' in animals) # Check if an element is in a set; prints \"True\"\n", 604 | "print('fish' in animals) # prints \"False\"" 605 | ] 606 | }, 607 | { 608 | "cell_type": "code", 609 | "execution_count": null, 610 | "metadata": {}, 611 | "outputs": [], 612 | "source": [ 613 | "animals.add('fish') # Add an element to a set\n", 614 | "print('fish' in animals) # Prints \"True\"\n", 615 | "print(len(animals)) # Number of elements in a set; prints \"3\"" 616 | ] 617 | }, 618 | { 619 | "cell_type": "code", 620 | "execution_count": null, 621 | "metadata": {}, 622 | "outputs": [], 623 | "source": [ 624 | "animals.add('cat') # Adding an element that is already in the set does nothing\n", 625 | "print(len(animals)) # Prints \"3\"" 626 | ] 627 | }, 628 | { 629 | "cell_type": "code", 630 | "execution_count": null, 631 | "metadata": { 632 | "scrolled": true 633 | }, 634 | "outputs": [], 635 | "source": [ 636 | "animals.remove('cat') # Remove an element from a set\n", 637 | "print(len(animals)) # Prints \"2\"" 638 | ] 639 | }, 640 | { 641 | "cell_type": "markdown", 642 | "metadata": {}, 643 | "source": [ 644 | "As usual, everything you want to know about sets can be found [in the documentation](https://docs.python.org/3.7/library/stdtypes.html#set)." 645 | ] 646 | }, 647 | { 648 | "cell_type": "markdown", 649 | "metadata": {}, 650 | "source": [ 651 | "**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:" 652 | ] 653 | }, 654 | { 655 | "cell_type": "code", 656 | "execution_count": null, 657 | "metadata": {}, 658 | "outputs": [], 659 | "source": [ 660 | "animals = {'cat', 'dog', 'fish', 'otter'}\n", 661 | "for idx, animal in enumerate(animals):\n", 662 | " print('#%d: %s' % (idx + 1, animal))\n", 663 | "# Prints \"#1: fish\", \"#2: dog\", \"#3: cat\"" 664 | ] 665 | }, 666 | { 667 | "cell_type": "markdown", 668 | "metadata": {}, 669 | "source": [ 670 | "**Set comprehensions**: Like lists and dictionaries, we can easily construct sets using set comprehensions:" 671 | ] 672 | }, 673 | { 674 | "cell_type": "code", 675 | "execution_count": null, 676 | "metadata": {}, 677 | "outputs": [], 678 | "source": [ 679 | "from math import sqrt\n", 680 | "nums = {int(sqrt(x)) for x in range(30)}\n", 681 | "print(nums) # Prints \"{0, 1, 2, 3, 4, 5}\"" 682 | ] 683 | }, 684 | { 685 | "cell_type": "markdown", 686 | "metadata": {}, 687 | "source": [ 688 | "### Tuples\n", 689 | "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:" 690 | ] 691 | }, 692 | { 693 | "cell_type": "code", 694 | "execution_count": null, 695 | "metadata": {}, 696 | "outputs": [], 697 | "source": [ 698 | "t=(1,2)\n", 699 | "print(t)\n", 700 | "print(type(t))\n", 701 | "print(t[0])\n", 702 | "\n" 703 | ] 704 | }, 705 | { 706 | "cell_type": "code", 707 | "execution_count": null, 708 | "metadata": { 709 | "scrolled": true 710 | }, 711 | "outputs": [], 712 | "source": [ 713 | "d = {(x, x + 1): x for x in range(10)} # Create a dictionary with tuple keys\n", 714 | "t = (5, 6) # Create a tuple\n", 715 | "print(type(t)) # Prints \"\"\n", 716 | "print(d[t]) # Prints \"5\"\n", 717 | "print(d[(1, 2)]) # Prints \"1\"" 718 | ] 719 | }, 720 | { 721 | "cell_type": "markdown", 722 | "metadata": {}, 723 | "source": [ 724 | "[The documentation](https://docs.python.org/3.7/tutorial/datastructures.html#tuples-and-sequences) has more information about tuples." 725 | ] 726 | }, 727 | { 728 | "cell_type": "markdown", 729 | "metadata": {}, 730 | "source": [ 731 | "## Functions\n", 732 | "Python functions are defined using the def keyword. For example:" 733 | ] 734 | }, 735 | { 736 | "cell_type": "code", 737 | "execution_count": null, 738 | "metadata": {}, 739 | "outputs": [], 740 | "source": [ 741 | "def sign(x):\n", 742 | " if x > 0:\n", 743 | " return 'positive'\n", 744 | " elif x < 0:\n", 745 | " return 'negative'\n", 746 | " else:\n", 747 | " return 'zero'\n", 748 | "\n", 749 | "for x in [-1, 0, 1]:\n", 750 | " print(sign(x))\n", 751 | "# Prints \"negative\", \"zero\", \"positive\"" 752 | ] 753 | }, 754 | { 755 | "cell_type": "markdown", 756 | "metadata": {}, 757 | "source": [ 758 | "We will often define functions to take optional keyword arguments, like this:" 759 | ] 760 | }, 761 | { 762 | "cell_type": "code", 763 | "execution_count": null, 764 | "metadata": {}, 765 | "outputs": [], 766 | "source": [ 767 | "def hello(name, loud=False):\n", 768 | " if loud:\n", 769 | " print('HELLO, %s!' % name.upper())\n", 770 | " else:\n", 771 | " print('Hello, %s' % name)\n", 772 | "\n", 773 | "hello('Bob') # Prints \"Hello, Bob\"\n", 774 | "hello('Fred', loud=True) # Prints \"HELLO, FRED!\"" 775 | ] 776 | }, 777 | { 778 | "cell_type": "markdown", 779 | "metadata": {}, 780 | "source": [ 781 | "There is a lot more information about Python functions [in the documentation](https://docs.python.org/3.7/tutorial/controlflow.html#defining-functions)." 782 | ] 783 | }, 784 | { 785 | "cell_type": "markdown", 786 | "metadata": {}, 787 | "source": [ 788 | "## Classes\n", 789 | "The syntax for defining classes in Python is straightforward:" 790 | ] 791 | }, 792 | { 793 | "cell_type": "code", 794 | "execution_count": null, 795 | "metadata": {}, 796 | "outputs": [], 797 | "source": [ 798 | "class Greeter(object):\n", 799 | "\n", 800 | " # Constructor\n", 801 | " def __init__(self, name):\n", 802 | " self.name = name # Create an instance variable\n", 803 | "\n", 804 | " # Instance method\n", 805 | " def greet(self, loud=False):\n", 806 | " if loud:\n", 807 | " print('HELLO, %s!' % self.name.upper())\n", 808 | " else:\n", 809 | " print('Hello, %s' % self.name)\n", 810 | "\n", 811 | "g = Greeter('Fred') # Construct an instance of the Greeter class\n", 812 | "g.greet() # Call an instance method; prints \"Hello, Fred\"\n", 813 | "g.greet(loud=True) # Call an instance method; prints \"HELLO, FRED!\"" 814 | ] 815 | }, 816 | { 817 | "cell_type": "markdown", 818 | "metadata": {}, 819 | "source": [ 820 | "You can read a lot more about Python classes [in the documentation](https://docs.python.org/3.7/tutorial/classes.html)." 821 | ] 822 | }, 823 | { 824 | "cell_type": "markdown", 825 | "metadata": {}, 826 | "source": [ 827 | "# Numpy\n", 828 | "[Numpy](http://www.numpy.org/) is the core library for scientific computing in Python. It provides a high-performance multidimensional array object, and tools for working with these arrays. If you are already familiar with MATLAB, you might find [this tutorial useful](https://docs.scipy.org/doc/numpy/user/numpy-for-matlab-users.html) to get started with Numpy." 829 | ] 830 | }, 831 | { 832 | "cell_type": "markdown", 833 | "metadata": {}, 834 | "source": [ 835 | "## Arrays\n", 836 | "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.\n", 837 | "\n", 838 | "We can initialize numpy arrays from nested Python lists, and access elements using square brackets:" 839 | ] 840 | }, 841 | { 842 | "cell_type": "code", 843 | "execution_count": null, 844 | "metadata": {}, 845 | "outputs": [], 846 | "source": [ 847 | "import numpy as np\n", 848 | "\n", 849 | "a = np.array([1, 2, 3]) # Create a rank 1 array\n", 850 | "print(type(a)) # Prints \"\"\n", 851 | "print(a.shape) # Prints \"(3,)\"\n", 852 | "print(a[0], a[1], a[2]) # Prints \"1 2 3\"" 853 | ] 854 | }, 855 | { 856 | "cell_type": "code", 857 | "execution_count": null, 858 | "metadata": {}, 859 | "outputs": [], 860 | "source": [ 861 | "a[0] = 5 # Change an element of the array\n", 862 | "print(a) # Prints \"[5, 2, 3]\"" 863 | ] 864 | }, 865 | { 866 | "cell_type": "code", 867 | "execution_count": null, 868 | "metadata": {}, 869 | "outputs": [], 870 | "source": [ 871 | "b = np.array([[1,2,3],[4,5,6]]) # Create a rank 2 array\n", 872 | "print(b.shape) # Prints \"(2, 3)\"\n", 873 | "print(b[0, 0], b[0, 1], b[1, 0]) # Prints \"1 2 4\"" 874 | ] 875 | }, 876 | { 877 | "cell_type": "markdown", 878 | "metadata": {}, 879 | "source": [ 880 | "Numpy also provides many functions to create arrays:" 881 | ] 882 | }, 883 | { 884 | "cell_type": "code", 885 | "execution_count": null, 886 | "metadata": {}, 887 | "outputs": [], 888 | "source": [ 889 | "import numpy as np\n", 890 | "\n", 891 | "a = np.zeros((2,2)) # Create an array of all zeros\n", 892 | "print(a) # Prints \"[[ 0. 0.]\n", 893 | " # [ 0. 0.]]\"" 894 | ] 895 | }, 896 | { 897 | "cell_type": "code", 898 | "execution_count": null, 899 | "metadata": {}, 900 | "outputs": [], 901 | "source": [ 902 | "b = np.ones((1,2)) # Create an array of all ones\n", 903 | "print(b) # Prints \"[[ 1. 1.]]\"" 904 | ] 905 | }, 906 | { 907 | "cell_type": "code", 908 | "execution_count": null, 909 | "metadata": {}, 910 | "outputs": [], 911 | "source": [ 912 | "c = np.full((2,2), 7) # Create a constant array\n", 913 | "print(c) # Prints \"[[ 7. 7.]\n", 914 | " # [ 7. 7.]]\"" 915 | ] 916 | }, 917 | { 918 | "cell_type": "code", 919 | "execution_count": null, 920 | "metadata": {}, 921 | "outputs": [], 922 | "source": [ 923 | "d = np.eye(2) # Create a 2x2 identity matrix\n", 924 | "print(d) # Prints \"[[ 1. 0.]\n", 925 | " # [ 0. 1.]]\"" 926 | ] 927 | }, 928 | { 929 | "cell_type": "code", 930 | "execution_count": null, 931 | "metadata": {}, 932 | "outputs": [], 933 | "source": [ 934 | "e = np.random.random((2,2)) # Create an array filled with random values\n", 935 | "print(e) # Might print \"[[ 0.91940167 0.08143941]\n", 936 | " # [ 0.68744134 0.87236687]]\"" 937 | ] 938 | }, 939 | { 940 | "cell_type": "markdown", 941 | "metadata": {}, 942 | "source": [ 943 | "You can read about other methods of array creation [in the documentation](http://docs.scipy.org/doc/numpy/user/basics.creation.html#arrays-creation)." 944 | ] 945 | }, 946 | { 947 | "cell_type": "markdown", 948 | "metadata": {}, 949 | "source": [ 950 | "## Array indexing\n", 951 | "Numpy offers several ways to index into arrays.\n", 952 | "\n", 953 | "**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:" 954 | ] 955 | }, 956 | { 957 | "cell_type": "code", 958 | "execution_count": null, 959 | "metadata": {}, 960 | "outputs": [], 961 | "source": [ 962 | "import numpy as np\n", 963 | "\n", 964 | "# Create the following rank 2 array with shape (3, 4)\n", 965 | "# [[ 1 2 3 4]\n", 966 | "# [ 5 6 7 8]\n", 967 | "# [ 9 10 11 12]]\n", 968 | "a = np.array([[1,2,3,4], [5,6,7,8], [9,10,11,12]])" 969 | ] 970 | }, 971 | { 972 | "cell_type": "code", 973 | "execution_count": null, 974 | "metadata": {}, 975 | "outputs": [], 976 | "source": [ 977 | "# Use slicing to pull out the subarray consisting of the first 2 rows\n", 978 | "# and columns 1 and 2; b is the following array of shape (2, 2):\n", 979 | "# [[2 3]\n", 980 | "# [6 7]]\n", 981 | "b = a[:2, 1:3]" 982 | ] 983 | }, 984 | { 985 | "cell_type": "code", 986 | "execution_count": null, 987 | "metadata": {}, 988 | "outputs": [], 989 | "source": [ 990 | "# A slice of an array is a view into the same data, so modifying it\n", 991 | "# will modify the original array.\n", 992 | "print(a[0, 1]) # Prints \"2\"\n", 993 | "b[0, 0] = 77 # b[0, 0] is the same piece of data as a[0, 1]\n", 994 | "print(a[0, 1]) # Prints \"77\"" 995 | ] 996 | }, 997 | { 998 | "cell_type": "markdown", 999 | "metadata": {}, 1000 | "source": [ 1001 | "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:" 1002 | ] 1003 | }, 1004 | { 1005 | "cell_type": "code", 1006 | "execution_count": null, 1007 | "metadata": {}, 1008 | "outputs": [], 1009 | "source": [ 1010 | "import numpy as np\n", 1011 | "\n", 1012 | "# Create the following rank 2 array with shape (3, 4)\n", 1013 | "# [[ 1 2 3 4]\n", 1014 | "# [ 5 6 7 8]\n", 1015 | "# [ 9 10 11 12]]\n", 1016 | "a = np.array([[1,2,3,4], [5,6,7,8], [9,10,11,12]])" 1017 | ] 1018 | }, 1019 | { 1020 | "cell_type": "code", 1021 | "execution_count": null, 1022 | "metadata": {}, 1023 | "outputs": [], 1024 | "source": [ 1025 | "# Two ways of accessing the data in the middle row of the array.\n", 1026 | "# Mixing integer indexing with slices yields an array of lower rank,\n", 1027 | "# while using only slices yields an array of the same rank as the\n", 1028 | "# original array:\n", 1029 | "row_r1 = a[1, :] # Rank 1 view of the second row of a\n", 1030 | "row_r2 = a[1:2, :] # Rank 2 view of the second row of a\n", 1031 | "print(row_r1, row_r1.shape) # Prints \"[5 6 7 8] (4,)\"\n", 1032 | "print(row_r2, row_r2.shape) # Prints \"[[5 6 7 8]] (1, 4)\"" 1033 | ] 1034 | }, 1035 | { 1036 | "cell_type": "code", 1037 | "execution_count": null, 1038 | "metadata": {}, 1039 | "outputs": [], 1040 | "source": [ 1041 | "# We can make the same distinction when accessing columns of an array:\n", 1042 | "col_r1 = a[:, 1]\n", 1043 | "col_r2 = a[:, 1:2]\n", 1044 | "print(col_r1, col_r1.shape) # Prints \"[ 2 6 10] (3,)\"\n", 1045 | "print(col_r2, col_r2.shape) # Prints \"[[ 2]\n", 1046 | " # [ 6]\n", 1047 | " # [10]] (3, 1)\"" 1048 | ] 1049 | }, 1050 | { 1051 | "cell_type": "markdown", 1052 | "metadata": {}, 1053 | "source": [ 1054 | "**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:" 1055 | ] 1056 | }, 1057 | { 1058 | "cell_type": "code", 1059 | "execution_count": null, 1060 | "metadata": {}, 1061 | "outputs": [], 1062 | "source": [ 1063 | "import numpy as np\n", 1064 | "\n", 1065 | "a = np.array([[1,2], [3, 4], [5, 6]])" 1066 | ] 1067 | }, 1068 | { 1069 | "cell_type": "code", 1070 | "execution_count": null, 1071 | "metadata": {}, 1072 | "outputs": [], 1073 | "source": [ 1074 | "# An example of integer array indexing.\n", 1075 | "# The returned array will have shape (3,) and\n", 1076 | "print(a[[0, 1, 2], [0, 1, 0]]) # Prints \"[1 4 5]\"" 1077 | ] 1078 | }, 1079 | { 1080 | "cell_type": "code", 1081 | "execution_count": null, 1082 | "metadata": {}, 1083 | "outputs": [], 1084 | "source": [ 1085 | "# The above example of integer array indexing is equivalent to this:\n", 1086 | "print(np.array([a[0, 0], a[1, 1], a[2, 0]])) # Prints \"[1 4 5]\"" 1087 | ] 1088 | }, 1089 | { 1090 | "cell_type": "code", 1091 | "execution_count": null, 1092 | "metadata": {}, 1093 | "outputs": [], 1094 | "source": [ 1095 | "# When using integer array indexing, you can reuse the same\n", 1096 | "# element from the source array:\n", 1097 | "print(a[[0, 0], [1, 1]]) # Prints \"[2 2]\"" 1098 | ] 1099 | }, 1100 | { 1101 | "cell_type": "code", 1102 | "execution_count": null, 1103 | "metadata": {}, 1104 | "outputs": [], 1105 | "source": [ 1106 | "# Equivalent to the previous integer array indexing example\n", 1107 | "print(np.array([a[0, 1], a[0, 1]])) # Prints \"[2 2]\"" 1108 | ] 1109 | }, 1110 | { 1111 | "cell_type": "markdown", 1112 | "metadata": {}, 1113 | "source": [ 1114 | "One useful trick with integer array indexing is selecting or mutating one element from each row of a matrix:" 1115 | ] 1116 | }, 1117 | { 1118 | "cell_type": "code", 1119 | "execution_count": null, 1120 | "metadata": {}, 1121 | "outputs": [], 1122 | "source": [ 1123 | "import numpy as np\n", 1124 | "\n", 1125 | "# Create a new array from which we will select elements\n", 1126 | "a = np.array([[1,2,3], [4,5,6], [7,8,9], [10, 11, 12]])\n", 1127 | "\n", 1128 | "print(a) # prints \"array([[ 1, 2, 3],\n", 1129 | " # [ 4, 5, 6],\n", 1130 | " # [ 7, 8, 9],\n", 1131 | " # [10, 11, 12]])\"" 1132 | ] 1133 | }, 1134 | { 1135 | "cell_type": "code", 1136 | "execution_count": null, 1137 | "metadata": {}, 1138 | "outputs": [], 1139 | "source": [ 1140 | "# Create an array of indices\n", 1141 | "b = np.array([0, 2, 0, 1])\n", 1142 | "\n", 1143 | "# Select one element from each row of a using the indices in b\n", 1144 | "print(a[np.arange(4), b]) # Prints \"[ 1 6 7 11]\"" 1145 | ] 1146 | }, 1147 | { 1148 | "cell_type": "code", 1149 | "execution_count": null, 1150 | "metadata": {}, 1151 | "outputs": [], 1152 | "source": [ 1153 | "# Mutate one element from each row of a using the indices in b\n", 1154 | "a[np.arange(4), b] += 10\n", 1155 | "\n", 1156 | "print(a) # prints \"array([[11, 2, 3],\n", 1157 | " # [ 4, 5, 16],\n", 1158 | " # [17, 8, 9],\n", 1159 | " # [10, 21, 12]])" 1160 | ] 1161 | }, 1162 | { 1163 | "cell_type": "markdown", 1164 | "metadata": {}, 1165 | "source": [ 1166 | "**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:" 1167 | ] 1168 | }, 1169 | { 1170 | "cell_type": "code", 1171 | "execution_count": null, 1172 | "metadata": {}, 1173 | "outputs": [], 1174 | "source": [ 1175 | "import numpy as np\n", 1176 | "\n", 1177 | "a = np.array([[1,2], [3, 4], [5, 6]])\n", 1178 | "\n", 1179 | "bool_idx = (a > 2) # Find the elements of a that are bigger than 2;\n", 1180 | " # this returns a numpy array of Booleans of the same\n", 1181 | " # shape as a, where each slot of bool_idx tells\n", 1182 | " # whether that element of a is > 2.\n", 1183 | "\n", 1184 | "print(bool_idx) # Prints \"[[False False]\n", 1185 | " # [ True True]\n", 1186 | " # [ True True]]\"" 1187 | ] 1188 | }, 1189 | { 1190 | "cell_type": "code", 1191 | "execution_count": null, 1192 | "metadata": {}, 1193 | "outputs": [], 1194 | "source": [ 1195 | "# We use boolean array indexing to construct a rank 1 array\n", 1196 | "# consisting of the elements of a corresponding to the True values\n", 1197 | "# of bool_idx\n", 1198 | "print(a[bool_idx]) # Prints \"[3 4 5 6]\"" 1199 | ] 1200 | }, 1201 | { 1202 | "cell_type": "code", 1203 | "execution_count": null, 1204 | "metadata": {}, 1205 | "outputs": [], 1206 | "source": [ 1207 | "# We can do all of the above in a single concise statement:\n", 1208 | "print(a[a > 2]) # Prints \"[3 4 5 6]\"" 1209 | ] 1210 | }, 1211 | { 1212 | "cell_type": "markdown", 1213 | "metadata": {}, 1214 | "source": [ 1215 | "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](http://docs.scipy.org/doc/numpy/reference/arrays.indexing.html)." 1216 | ] 1217 | }, 1218 | { 1219 | "cell_type": "markdown", 1220 | "metadata": {}, 1221 | "source": [ 1222 | "## Datatypes\n", 1223 | "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:" 1224 | ] 1225 | }, 1226 | { 1227 | "cell_type": "code", 1228 | "execution_count": null, 1229 | "metadata": {}, 1230 | "outputs": [], 1231 | "source": [ 1232 | "import numpy as np\n", 1233 | "\n", 1234 | "x = np.array([1, 2]) # Let numpy choose the datatype\n", 1235 | "print(x.dtype) # Prints \"int64\"" 1236 | ] 1237 | }, 1238 | { 1239 | "cell_type": "code", 1240 | "execution_count": null, 1241 | "metadata": {}, 1242 | "outputs": [], 1243 | "source": [ 1244 | "x = np.array([1.0, 2.0]) # Let numpy choose the datatype\n", 1245 | "print(x.dtype) # Prints \"float64\"" 1246 | ] 1247 | }, 1248 | { 1249 | "cell_type": "code", 1250 | "execution_count": null, 1251 | "metadata": {}, 1252 | "outputs": [], 1253 | "source": [ 1254 | "x = np.array([1, 2], dtype=np.int64) # Force a particular datatype\n", 1255 | "print(x.dtype)\n" 1256 | ] 1257 | }, 1258 | { 1259 | "cell_type": "markdown", 1260 | "metadata": {}, 1261 | "source": [ 1262 | "You can read all about numpy datatypes [in the documentation](http://docs.scipy.org/doc/numpy/reference/arrays.dtypes.html)." 1263 | ] 1264 | }, 1265 | { 1266 | "cell_type": "markdown", 1267 | "metadata": {}, 1268 | "source": [ 1269 | "## Array math\n", 1270 | "Basic mathematical functions operate elementwise on arrays, and are available both as operator overloads and as functions in the numpy module:" 1271 | ] 1272 | }, 1273 | { 1274 | "cell_type": "code", 1275 | "execution_count": null, 1276 | "metadata": {}, 1277 | "outputs": [], 1278 | "source": [ 1279 | "import numpy as np\n", 1280 | "\n", 1281 | "x = np.array([[1,2],[3,4]], dtype=np.float64)\n", 1282 | "y = np.array([[5,6],[7,8]], dtype=np.float64)" 1283 | ] 1284 | }, 1285 | { 1286 | "cell_type": "code", 1287 | "execution_count": null, 1288 | "metadata": {}, 1289 | "outputs": [], 1290 | "source": [ 1291 | "# Elementwise sum; both produce the array\n", 1292 | "# [[ 6.0 8.0]\n", 1293 | "# [10.0 12.0]]\n", 1294 | "print(x + y)\n", 1295 | "print(np.add(x, y))" 1296 | ] 1297 | }, 1298 | { 1299 | "cell_type": "code", 1300 | "execution_count": null, 1301 | "metadata": {}, 1302 | "outputs": [], 1303 | "source": [ 1304 | "# Elementwise difference; both produce the array\n", 1305 | "# [[-4.0 -4.0]\n", 1306 | "# [-4.0 -4.0]]\n", 1307 | "print(x - y)\n", 1308 | "print(np.subtract(x, y))" 1309 | ] 1310 | }, 1311 | { 1312 | "cell_type": "code", 1313 | "execution_count": null, 1314 | "metadata": {}, 1315 | "outputs": [], 1316 | "source": [ 1317 | "# Elementwise product; both produce the array\n", 1318 | "# [[ 5.0 12.0]\n", 1319 | "# [21.0 32.0]]\n", 1320 | "print(x * y)\n", 1321 | "print(np.multiply(x, y))" 1322 | ] 1323 | }, 1324 | { 1325 | "cell_type": "code", 1326 | "execution_count": null, 1327 | "metadata": {}, 1328 | "outputs": [], 1329 | "source": [ 1330 | "# Elementwise division; both produce the array\n", 1331 | "# [[ 0.2 0.33333333]\n", 1332 | "# [ 0.42857143 0.5 ]]\n", 1333 | "print(x / y)\n", 1334 | "print(np.divide(x, y))" 1335 | ] 1336 | }, 1337 | { 1338 | "cell_type": "code", 1339 | "execution_count": null, 1340 | "metadata": {}, 1341 | "outputs": [], 1342 | "source": [ 1343 | "# Elementwise square root; produces the array\n", 1344 | "# [[ 1. 1.41421356]\n", 1345 | "# [ 1.73205081 2. ]]\n", 1346 | "print(np.sqrt(x))" 1347 | ] 1348 | }, 1349 | { 1350 | "cell_type": "markdown", 1351 | "metadata": {}, 1352 | "source": [ 1353 | "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` is available both as a function in the numpy module and as an instance method of array objects:" 1354 | ] 1355 | }, 1356 | { 1357 | "cell_type": "code", 1358 | "execution_count": null, 1359 | "metadata": {}, 1360 | "outputs": [], 1361 | "source": [ 1362 | "import numpy as np\n", 1363 | "\n", 1364 | "x = np.array([[1,2],[3,4]])\n", 1365 | "y = np.array([[5,6],[7,8]])\n", 1366 | "\n", 1367 | "v = np.array([9,10])\n", 1368 | "w = np.array([11, 12])" 1369 | ] 1370 | }, 1371 | { 1372 | "cell_type": "code", 1373 | "execution_count": null, 1374 | "metadata": {}, 1375 | "outputs": [], 1376 | "source": [ 1377 | "# Inner product of vectors; both produce 219\n", 1378 | "print(v.dot(w))\n", 1379 | "print(np.dot(v, w))" 1380 | ] 1381 | }, 1382 | { 1383 | "cell_type": "code", 1384 | "execution_count": null, 1385 | "metadata": {}, 1386 | "outputs": [], 1387 | "source": [ 1388 | "# Matrix / vector product; both produce the rank 1 array [29 67]\n", 1389 | "print(x.dot(v))\n", 1390 | "print(np.dot(x, v))" 1391 | ] 1392 | }, 1393 | { 1394 | "cell_type": "code", 1395 | "execution_count": null, 1396 | "metadata": {}, 1397 | "outputs": [], 1398 | "source": [ 1399 | "# Matrix / matrix product; both produce the rank 2 array\n", 1400 | "# [[19 22]\n", 1401 | "# [43 50]]\n", 1402 | "print(x.dot(y))\n", 1403 | "print(np.dot(x, y))" 1404 | ] 1405 | }, 1406 | { 1407 | "cell_type": "markdown", 1408 | "metadata": {}, 1409 | "source": [ 1410 | "Numpy provides many useful functions for performing computations on arrays; one of the most useful is `sum`:" 1411 | ] 1412 | }, 1413 | { 1414 | "cell_type": "code", 1415 | "execution_count": null, 1416 | "metadata": {}, 1417 | "outputs": [], 1418 | "source": [ 1419 | "import numpy as np\n", 1420 | "\n", 1421 | "x = np.array([[1,2],[3,4]])\n", 1422 | "\n", 1423 | "print(np.sum(x)) # Compute sum of all elements; prints \"10\"\n", 1424 | "print(np.sum(x, axis=0)) # Compute sum of each column; prints \"[4 6]\"\n", 1425 | "print(np.sum(x, axis=1)) # Compute sum of each row; prints \"[3 7]\"" 1426 | ] 1427 | }, 1428 | { 1429 | "cell_type": "markdown", 1430 | "metadata": {}, 1431 | "source": [ 1432 | "You can find the full list of mathematical functions provided by numpy [in the documentation](http://docs.scipy.org/doc/numpy/reference/routines.math.html)." 1433 | ] 1434 | }, 1435 | { 1436 | "cell_type": "markdown", 1437 | "metadata": {}, 1438 | "source": [ 1439 | "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:" 1440 | ] 1441 | }, 1442 | { 1443 | "cell_type": "code", 1444 | "execution_count": null, 1445 | "metadata": {}, 1446 | "outputs": [], 1447 | "source": [ 1448 | "import numpy as np\n", 1449 | "\n", 1450 | "x = np.array([[1,2], [3,4]])\n", 1451 | "print(x) # Prints \"[[1 2]\n", 1452 | " # [3 4]]\"\n", 1453 | "print(x.T) # Prints \"[[1 3]\n", 1454 | " # [2 4]]\"" 1455 | ] 1456 | }, 1457 | { 1458 | "cell_type": "code", 1459 | "execution_count": null, 1460 | "metadata": {}, 1461 | "outputs": [], 1462 | "source": [ 1463 | "# Note that taking the transpose of a rank 1 array does nothing:\n", 1464 | "v = np.array([1,2,3])\n", 1465 | "print(v) # Prints \"[1 2 3]\"\n", 1466 | "print(v.T) # Prints \"[1 2 3]\"" 1467 | ] 1468 | }, 1469 | { 1470 | "cell_type": "markdown", 1471 | "metadata": {}, 1472 | "source": [ 1473 | "Numpy provides many more functions for manipulating arrays; you can see the full list [in the documentation](http://docs.scipy.org/doc/numpy/reference/routines.array-manipulation.html)." 1474 | ] 1475 | }, 1476 | { 1477 | "cell_type": "markdown", 1478 | "metadata": {}, 1479 | "source": [ 1480 | "## Broadcasting\n", 1481 | "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", 1482 | "\n", 1483 | "For example, suppose that we want to add a constant vector to each row of a matrix. We could do it like this:" 1484 | ] 1485 | }, 1486 | { 1487 | "cell_type": "code", 1488 | "execution_count": null, 1489 | "metadata": {}, 1490 | "outputs": [], 1491 | "source": [ 1492 | "import numpy as np\n", 1493 | "\n", 1494 | "# We will add the vector v to each row of the matrix x,\n", 1495 | "# storing the result in the matrix y\n", 1496 | "x = np.array([[1,2,3], [4,5,6], [7,8,9], [10, 11, 12]])\n", 1497 | "v = np.array([1, 0, 1])\n", 1498 | "y = np.empty_like(x) # Create an empty matrix with the same shape as x\n", 1499 | "\n", 1500 | "# Add the vector v to each row of the matrix x with an explicit loop\n", 1501 | "for i in range(4):\n", 1502 | " y[i, :] = x[i, :] + v\n", 1503 | " \n", 1504 | "# Now y is the following\n", 1505 | "# [[ 2 2 4]\n", 1506 | "# [ 5 5 7]\n", 1507 | "# [ 8 8 10]\n", 1508 | "# [11 11 13]]\n", 1509 | "print(y)" 1510 | ] 1511 | }, 1512 | { 1513 | "cell_type": "markdown", 1514 | "metadata": {}, 1515 | "source": [ 1516 | "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:" 1517 | ] 1518 | }, 1519 | { 1520 | "cell_type": "code", 1521 | "execution_count": null, 1522 | "metadata": {}, 1523 | "outputs": [], 1524 | "source": [ 1525 | "import numpy as np\n", 1526 | "\n", 1527 | "# We will add the vector v to each row of the matrix x,\n", 1528 | "# storing the result in the matrix y\n", 1529 | "x = np.array([[1,2,3], [4,5,6], [7,8,9], [10, 11, 12]])\n", 1530 | "v = np.array([1, 0, 1])\n", 1531 | "vv = np.tile(v, (4, 1)) # Stack 4 copies of v on top of each other\n", 1532 | "print(vv) # Prints \"[[1 0 1]\n", 1533 | " # [1 0 1]\n", 1534 | " # [1 0 1]\n", 1535 | " # [1 0 1]]\"" 1536 | ] 1537 | }, 1538 | { 1539 | "cell_type": "code", 1540 | "execution_count": null, 1541 | "metadata": {}, 1542 | "outputs": [], 1543 | "source": [ 1544 | "y = x + vv # Add x and vv elementwise\n", 1545 | "print(y) # Prints \"[[ 2 2 4\n", 1546 | " # [ 5 5 7]\n", 1547 | " # [ 8 8 10]\n", 1548 | " # [11 11 13]]\"" 1549 | ] 1550 | }, 1551 | { 1552 | "cell_type": "markdown", 1553 | "metadata": {}, 1554 | "source": [ 1555 | "Numpy broadcasting allows us to perform this computation without actually creating multiple copies of `v`. Consider this version, using broadcasting:" 1556 | ] 1557 | }, 1558 | { 1559 | "cell_type": "code", 1560 | "execution_count": null, 1561 | "metadata": {}, 1562 | "outputs": [], 1563 | "source": [ 1564 | "import numpy as np\n", 1565 | "\n", 1566 | "# We will add the vector v to each row of the matrix x,\n", 1567 | "# storing the result in the matrix y\n", 1568 | "x = np.array([[1,2,3], [4,5,6], [7,8,9], [10, 11, 12]])\n", 1569 | "v = np.array([1, 0, 1])\n", 1570 | "y = x + v # Add v to each row of x using broadcasting\n", 1571 | "print(y) # Prints \"[[ 2 2 4]\n", 1572 | " # [ 5 5 7]\n", 1573 | " # [ 8 8 10]\n", 1574 | " # [11 11 13]]\"" 1575 | ] 1576 | }, 1577 | { 1578 | "cell_type": "markdown", 1579 | "metadata": {}, 1580 | "source": [ 1581 | "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." 1582 | ] 1583 | }, 1584 | { 1585 | "cell_type": "markdown", 1586 | "metadata": {}, 1587 | "source": [ 1588 | "Broadcasting two arrays together follows these rules:\n", 1589 | "\n", 1590 | "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", 1591 | "1. 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", 1592 | "1. The arrays can be broadcast together if they are compatible in all dimensions.\n", 1593 | "1. After broadcasting, each array behaves as if it had shape equal to the elementwise maximum of shapes of the two input arrays.\n", 1594 | "1. 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", 1595 | "If this explanation does not make sense, try reading the explanation [from the documentation](http://docs.scipy.org/doc/numpy/user/basics.broadcasting.html) or [this explanation](http://wiki.scipy.org/EricsBroadcastingDoc).\n", 1596 | "\n", 1597 | "Functions that support broadcasting are known as universal functions. You can find the list of all universal functions [in the documentation](http://docs.scipy.org/doc/numpy/reference/ufuncs.html#available-ufuncs).\n", 1598 | "\n", 1599 | "Here are some applications of broadcasting:" 1600 | ] 1601 | }, 1602 | { 1603 | "cell_type": "code", 1604 | "execution_count": null, 1605 | "metadata": {}, 1606 | "outputs": [], 1607 | "source": [ 1608 | "import numpy as np\n", 1609 | "\n", 1610 | "# Compute outer product of vectors\n", 1611 | "v = np.array([1,2,3]) # v has shape (3,)\n", 1612 | "w = np.array([4,5]) # w has shape (2,)\n", 1613 | "# To compute an outer product, we first reshape v to be a column\n", 1614 | "# vector of shape (3, 1); we can then broadcast it against w to yield\n", 1615 | "# an output of shape (3, 2), which is the outer product of v and w:\n", 1616 | "# [[ 4 5]\n", 1617 | "# [ 8 10]\n", 1618 | "# [12 15]]\n", 1619 | "print(np.reshape(v, (3, 1)) * w)" 1620 | ] 1621 | }, 1622 | { 1623 | "cell_type": "code", 1624 | "execution_count": null, 1625 | "metadata": {}, 1626 | "outputs": [], 1627 | "source": [ 1628 | "# Add a vector to each row of a matrix\n", 1629 | "x = np.array([[1,2,3], [4,5,6]])\n", 1630 | "# x has shape (2, 3) and v has shape (3,) so they broadcast to (2, 3),\n", 1631 | "# giving the following matrix:\n", 1632 | "# [[2 4 6]\n", 1633 | "# [5 7 9]]\n", 1634 | "print(x + v)" 1635 | ] 1636 | }, 1637 | { 1638 | "cell_type": "code", 1639 | "execution_count": null, 1640 | "metadata": {}, 1641 | "outputs": [], 1642 | "source": [ 1643 | "# Add a vector to each column of a matrix\n", 1644 | "# x has shape (2, 3) and w has shape (2,).\n", 1645 | "# If we transpose x then it has shape (3, 2) and can be broadcast\n", 1646 | "# against w to yield a result of shape (3, 2); transposing this result\n", 1647 | "# yields the final result of shape (2, 3) which is the matrix x with\n", 1648 | "# the vector w added to each column. Gives the following matrix:\n", 1649 | "# [[ 5 6 7]\n", 1650 | "# [ 9 10 11]]\n", 1651 | "print((x.T + w).T)" 1652 | ] 1653 | }, 1654 | { 1655 | "cell_type": "code", 1656 | "execution_count": null, 1657 | "metadata": {}, 1658 | "outputs": [], 1659 | "source": [ 1660 | "# Another solution is to reshape w to be a column vector of shape (2, 1);\n", 1661 | "# we can then broadcast it directly against x to produce the same\n", 1662 | "# output.\n", 1663 | "print(x + np.reshape(w, (2, 1)))" 1664 | ] 1665 | }, 1666 | { 1667 | "cell_type": "code", 1668 | "execution_count": null, 1669 | "metadata": {}, 1670 | "outputs": [], 1671 | "source": [ 1672 | "# Multiply a matrix by a constant:\n", 1673 | "# x has shape (2, 3). Numpy treats scalars as arrays of shape ();\n", 1674 | "# these can be broadcast together to shape (2, 3), producing the\n", 1675 | "# following array:\n", 1676 | "# [[ 2 4 6]\n", 1677 | "# [ 8 10 12]]\n", 1678 | "print(x * 2)" 1679 | ] 1680 | }, 1681 | { 1682 | "cell_type": "markdown", 1683 | "metadata": {}, 1684 | "source": [ 1685 | "Broadcasting typically makes your code more concise and faster, so you should strive to use it where possible." 1686 | ] 1687 | }, 1688 | { 1689 | "cell_type": "markdown", 1690 | "metadata": {}, 1691 | "source": [ 1692 | "## Numpy Documentation\n", 1693 | "This brief overview has touched on many of the important things that you need to know about numpy, but is far from complete. Check out the [numpy reference](http://docs.scipy.org/doc/numpy/reference/) to find out much more about numpy." 1694 | ] 1695 | }, 1696 | { 1697 | "cell_type": "markdown", 1698 | "metadata": {}, 1699 | "source": [ 1700 | "# SciPy\n", 1701 | "Numpy provides a high-performance multidimensional array and basic tools to compute with and manipulate these arrays. [SciPy](http://docs.scipy.org/doc/scipy/reference/) builds on this, and provides a large number of functions that operate on numpy arrays and are useful for different types of scientific and engineering applications.\n", 1702 | "\n", 1703 | "The best way to get familiar with SciPy is to [browse the documentation](http://docs.scipy.org/doc/scipy/reference/index.html). We will highlight some parts of SciPy that you might find useful for this class." 1704 | ] 1705 | }, 1706 | { 1707 | "cell_type": "markdown", 1708 | "metadata": {}, 1709 | "source": [ 1710 | "## Image operations\n", 1711 | "SciPy provides some basic functions to work with images. For example, it has functions to read images from disk into numpy arrays, to write numpy arrays to disk as images, and to resize images. Here is a simple example that showcases these functions (**some SciPy methods were deprecated after the original production of this tutorial, imports were adapted in order to keep the code working**):" 1712 | ] 1713 | }, 1714 | { 1715 | "cell_type": "code", 1716 | "execution_count": null, 1717 | "metadata": {}, 1718 | "outputs": [], 1719 | "source": [ 1720 | "import numpy as np\n", 1721 | "from imageio import imread, imwrite\n", 1722 | "from skimage.transform import resize\n", 1723 | "import matplotlib.pyplot as plt\n", 1724 | "\n", 1725 | "# Read an JPEG image into a numpy array\n", 1726 | "img = imread('../assets/cat.jpg')\n", 1727 | "print(img.dtype, img.shape) # Prints \"uint8 (400, 248, 3)\"\n", 1728 | "\n", 1729 | "# We can tint the image by scaling each of the color channels\n", 1730 | "# by a different scalar constant. The image has shape (400, 248, 3);\n", 1731 | "# we multiply it by the array [1, 0.95, 0.9] of shape (3,);\n", 1732 | "# numpy broadcasting means that this leaves the red channel unchanged,\n", 1733 | "# and multiplies the green and blue channels by 0.95 and 0.9\n", 1734 | "# respectively.\n", 1735 | "img_tinted = (img * [1, 0.95, 0.9])\n", 1736 | "print(img_tinted.dtype, img_tinted.shape) # Prints \"float64 (400, 248, 3)\"\n", 1737 | "\n", 1738 | "# Resize the tinted image to be 300 by 300 pixels.\n", 1739 | "img_tinted = resize(img_tinted, (300, 300)).astype(dtype=np.uint8)\n", 1740 | "print(img_tinted.dtype, img_tinted.shape) # Prints \"uint8 (300, 248, 3)\"\n", 1741 | "\n", 1742 | "# Write the tinted image back to disk\n", 1743 | "imwrite('../assets/cat_tinted.jpg', img_tinted)" 1744 | ] 1745 | }, 1746 | { 1747 | "cell_type": "code", 1748 | "execution_count": null, 1749 | "metadata": {}, 1750 | "outputs": [], 1751 | "source": [ 1752 | "# Show original images - Matplotlib will be presented later\n", 1753 | "plt.imshow(img)\n", 1754 | "plt.show()" 1755 | ] 1756 | }, 1757 | { 1758 | "cell_type": "code", 1759 | "execution_count": null, 1760 | "metadata": {}, 1761 | "outputs": [], 1762 | "source": [ 1763 | "# Show manipulated image\n", 1764 | "plt.imshow(img_tinted)\n", 1765 | "plt.show()" 1766 | ] 1767 | }, 1768 | { 1769 | "cell_type": "markdown", 1770 | "metadata": {}, 1771 | "source": [ 1772 | "## MATLAB files\n", 1773 | "The functions `scipy.io.loadmat` and `scipy.io.savemat` allow you to read and write MATLAB files. You can read about them [in the documentation](http://docs.scipy.org/doc/scipy/reference/io.html)." 1774 | ] 1775 | }, 1776 | { 1777 | "cell_type": "markdown", 1778 | "metadata": {}, 1779 | "source": [ 1780 | "## Distance between points\n", 1781 | "SciPy defines some useful functions for computing distances between sets of points.\n", 1782 | "\n", 1783 | "The function `scipy.spatial.distance.pdist` computes the distance between all pairs of points in a given set:" 1784 | ] 1785 | }, 1786 | { 1787 | "cell_type": "code", 1788 | "execution_count": null, 1789 | "metadata": {}, 1790 | "outputs": [], 1791 | "source": [ 1792 | "import numpy as np\n", 1793 | "from scipy.spatial.distance import pdist, squareform\n", 1794 | "\n", 1795 | "# Create the following array where each row is a point in 2D space:\n", 1796 | "# [[0 1]\n", 1797 | "# [1 0]\n", 1798 | "# [2 0]]\n", 1799 | "x = np.array([[0, 1], [1, 0], [2, 0]])\n", 1800 | "print(x)" 1801 | ] 1802 | }, 1803 | { 1804 | "cell_type": "code", 1805 | "execution_count": null, 1806 | "metadata": {}, 1807 | "outputs": [], 1808 | "source": [ 1809 | "# Compute the Euclidean distance between all rows of x.\n", 1810 | "# d[i, j] is the Euclidean distance between x[i, :] and x[j, :],\n", 1811 | "# and d is the following array:\n", 1812 | "# [[ 0. 1.41421356 2.23606798]\n", 1813 | "# [ 1.41421356 0. 1. ]\n", 1814 | "# [ 2.23606798 1. 0. ]]\n", 1815 | "d = squareform(pdist(x, 'euclidean'))\n", 1816 | "print(d)" 1817 | ] 1818 | }, 1819 | { 1820 | "cell_type": "markdown", 1821 | "metadata": {}, 1822 | "source": [ 1823 | "You can read all the details about this function [in the documentation](http://docs.scipy.org/doc/scipy/reference/generated/scipy.spatial.distance.pdist.html).\n", 1824 | "\n", 1825 | "A similar function (`scipy.spatial.distance.cdist`) computes the distance between all pairs across two sets of points; you can read about it [in the documentation](http://docs.scipy.org/doc/scipy/reference/generated/scipy.spatial.distance.cdist.html)." 1826 | ] 1827 | }, 1828 | { 1829 | "cell_type": "markdown", 1830 | "metadata": {}, 1831 | "source": [ 1832 | "# Matplotlib\n", 1833 | "[Matplotlib](http://matplotlib.org/) 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." 1834 | ] 1835 | }, 1836 | { 1837 | "cell_type": "markdown", 1838 | "metadata": {}, 1839 | "source": [ 1840 | "## Plotting\n", 1841 | "The most important function in matplotlib is `plot`, which allows you to plot 2D data. Here is a simple example:" 1842 | ] 1843 | }, 1844 | { 1845 | "cell_type": "code", 1846 | "execution_count": null, 1847 | "metadata": {}, 1848 | "outputs": [], 1849 | "source": [ 1850 | "import numpy as np\n", 1851 | "import matplotlib.pyplot as plt\n", 1852 | "\n", 1853 | "# Compute the x and y coordinates for points on a sine curve\n", 1854 | "x = np.arange(0, 3 * np.pi, 0.1)\n", 1855 | "y = np.sin(x)\n", 1856 | "\n", 1857 | "# Plot the points using matplotlib\n", 1858 | "plt.plot(x, y)\n", 1859 | "plt.show() # You must call plt.show() to make graphics appear." 1860 | ] 1861 | }, 1862 | { 1863 | "cell_type": "markdown", 1864 | "metadata": {}, 1865 | "source": [ 1866 | "With just a little bit of extra work we can easily plot multiple lines at once, and add a title, legend, and axis labels:" 1867 | ] 1868 | }, 1869 | { 1870 | "cell_type": "code", 1871 | "execution_count": null, 1872 | "metadata": {}, 1873 | "outputs": [], 1874 | "source": [ 1875 | "import numpy as np\n", 1876 | "import matplotlib.pyplot as plt\n", 1877 | "\n", 1878 | "# Compute the x and y coordinates for points on sine and cosine curves\n", 1879 | "x = np.arange(0, 3 * np.pi, 0.1)\n", 1880 | "y_sin = np.sin(x)\n", 1881 | "y_cos = np.cos(x)\n", 1882 | "\n", 1883 | "# Plot the points using matplotlib\n", 1884 | "plt.plot(x, y_sin)\n", 1885 | "plt.plot(x, y_cos)\n", 1886 | "plt.xlabel('x axis label')\n", 1887 | "plt.ylabel('y axis label')\n", 1888 | "plt.title('Sine and Cosine')\n", 1889 | "plt.legend(['Sine', 'Cosine'])\n", 1890 | "plt.show()" 1891 | ] 1892 | }, 1893 | { 1894 | "cell_type": "markdown", 1895 | "metadata": {}, 1896 | "source": [ 1897 | "You can read much more about the plot function [in the documentation](http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.plot)." 1898 | ] 1899 | }, 1900 | { 1901 | "cell_type": "markdown", 1902 | "metadata": {}, 1903 | "source": [ 1904 | "## Subplots\n", 1905 | "You can plot different things in the same figure using the `subplot` function. Here is an example:" 1906 | ] 1907 | }, 1908 | { 1909 | "cell_type": "code", 1910 | "execution_count": null, 1911 | "metadata": {}, 1912 | "outputs": [], 1913 | "source": [ 1914 | "import numpy as np\n", 1915 | "import matplotlib.pyplot as plt\n", 1916 | "\n", 1917 | "# Compute the x and y coordinates for points on sine and cosine curves\n", 1918 | "x = np.arange(0, 3 * np.pi, 0.1)\n", 1919 | "y_sin = np.sin(x)\n", 1920 | "y_cos = np.cos(x)\n", 1921 | "\n", 1922 | "# Set up a subplot grid that has height 2 and width 1,\n", 1923 | "# and set the first such subplot as active.\n", 1924 | "plt.subplot(2, 1, 1)\n", 1925 | "\n", 1926 | "# Make the first plot\n", 1927 | "plt.plot(x, y_sin)\n", 1928 | "plt.title('Sine')\n", 1929 | "\n", 1930 | "# Set the second subplot as active, and make the second plot.\n", 1931 | "plt.subplot(2, 1, 2)\n", 1932 | "plt.plot(x, y_cos)\n", 1933 | "plt.title('Cosine')\n", 1934 | "\n", 1935 | "# Show the figure.\n", 1936 | "plt.show()" 1937 | ] 1938 | }, 1939 | { 1940 | "cell_type": "markdown", 1941 | "metadata": {}, 1942 | "source": [ 1943 | "You can read much more about the `subplot` function [in the documentation](http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.subplot)." 1944 | ] 1945 | }, 1946 | { 1947 | "cell_type": "markdown", 1948 | "metadata": {}, 1949 | "source": [ 1950 | "## Images\n", 1951 | "You can use the `imshow` function to show images. Here is an example:" 1952 | ] 1953 | }, 1954 | { 1955 | "cell_type": "code", 1956 | "execution_count": null, 1957 | "metadata": {}, 1958 | "outputs": [], 1959 | "source": [ 1960 | "import numpy as np\n", 1961 | "from imageio import imread\n", 1962 | "import matplotlib.pyplot as plt\n", 1963 | "\n", 1964 | "img = imread('../assets/cat.jpg')\n", 1965 | "img_tinted = img * [1, 0.95, 0.9]\n", 1966 | "\n", 1967 | "# Show the original image\n", 1968 | "plt.subplot(1, 2, 1)\n", 1969 | "plt.imshow(img)\n", 1970 | "\n", 1971 | "# Show the tinted image\n", 1972 | "plt.subplot(1, 2, 2)\n", 1973 | "\n", 1974 | "# A slight gotcha with imshow is that it might give strange results\n", 1975 | "# if presented with data that is not uint8. To work around this, we\n", 1976 | "# explicitly cast the image to uint8 before displaying it.\n", 1977 | "plt.imshow(np.uint8(img_tinted))\n", 1978 | "plt.show()" 1979 | ] 1980 | }, 1981 | { 1982 | "cell_type": "code", 1983 | "execution_count": null, 1984 | "metadata": {}, 1985 | "outputs": [], 1986 | "source": [] 1987 | }, 1988 | { 1989 | "cell_type": "code", 1990 | "execution_count": null, 1991 | "metadata": {}, 1992 | "outputs": [], 1993 | "source": [] 1994 | }, 1995 | { 1996 | "cell_type": "code", 1997 | "execution_count": null, 1998 | "metadata": {}, 1999 | "outputs": [], 2000 | "source": [] 2001 | }, 2002 | { 2003 | "cell_type": "code", 2004 | "execution_count": null, 2005 | "metadata": {}, 2006 | "outputs": [], 2007 | "source": [] 2008 | } 2009 | ], 2010 | "metadata": { 2011 | "kernelspec": { 2012 | "display_name": "Python 3", 2013 | "language": "python", 2014 | "name": "python3" 2015 | }, 2016 | "language_info": { 2017 | "codemirror_mode": { 2018 | "name": "ipython", 2019 | "version": 3 2020 | }, 2021 | "file_extension": ".py", 2022 | "mimetype": "text/x-python", 2023 | "name": "python", 2024 | "nbconvert_exporter": "python", 2025 | "pygments_lexer": "ipython3", 2026 | "version": "3.7.6" 2027 | } 2028 | }, 2029 | "nbformat": 4, 2030 | "nbformat_minor": 2 2031 | } 2032 | -------------------------------------------------------------------------------- /tutorials/python/cs228-python-tutorial.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "metadata": { 3 | "name": "", 4 | "signature": "sha256:6248a0767da3cc11604f053c1e608074ae344353e7b050c42d8b2f7c494d7c3e" 5 | }, 6 | "nbformat": 3, 7 | "nbformat_minor": 0, 8 | "worksheets": [ 9 | { 10 | "cells": [ 11 | { 12 | "cell_type": "heading", 13 | "level": 1, 14 | "metadata": {}, 15 | "source": [ 16 | "CS228 Python Tutorial" 17 | ] 18 | }, 19 | { 20 | "cell_type": "markdown", 21 | "metadata": {}, 22 | "source": [ 23 | "Adapted by [Volodymyr Kuleshov](http://web.stanford.edu/~kuleshov/) and [Isaac Caswell](https://symsys.stanford.edu/viewing/symsysaffiliate/21335) from the `CS231n` Python tutorial by Justin Johnson (http://cs231n.github.io/python-numpy-tutorial/)." 24 | ] 25 | }, 26 | { 27 | "cell_type": "heading", 28 | "level": 2, 29 | "metadata": {}, 30 | "source": [ 31 | "Introduction" 32 | ] 33 | }, 34 | { 35 | "cell_type": "markdown", 36 | "metadata": {}, 37 | "source": [ 38 | "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", 39 | "\n", 40 | "We expect that many of you will have some experience with Python and numpy; for the rest of you, 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", 41 | "\n", 42 | "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-dev/user/numpy-for-matlab-users.html)." 43 | ] 44 | }, 45 | { 46 | "cell_type": "markdown", 47 | "metadata": {}, 48 | "source": [ 49 | "In this tutorial, we will cover:\n", 50 | "\n", 51 | "* Basic Python: Basic data types (Containers, Lists, Dictionaries, Sets, Tuples), Functions, Classes\n", 52 | "* Numpy: Arrays, Array indexing, Datatypes, Array math, Broadcasting\n", 53 | "* Matplotlib: Plotting, Subplots, Images\n", 54 | "* IPython: Creating notebooks, Typical workflows" 55 | ] 56 | }, 57 | { 58 | "cell_type": "heading", 59 | "level": 2, 60 | "metadata": {}, 61 | "source": [ 62 | "Basics of Python" 63 | ] 64 | }, 65 | { 66 | "cell_type": "markdown", 67 | "metadata": {}, 68 | "source": [ 69 | "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:" 70 | ] 71 | }, 72 | { 73 | "cell_type": "code", 74 | "collapsed": false, 75 | "input": [ 76 | "def quicksort(arr):\n", 77 | " if len(arr) <= 1:\n", 78 | " return arr\n", 79 | " pivot = arr[len(arr) // 2]\n", 80 | " left = [x for x in arr if x < pivot]\n", 81 | " middle = [x for x in arr if x == pivot]\n", 82 | " right = [x for x in arr if x > pivot]\n", 83 | " return quicksort(left) + middle + quicksort(right)\n", 84 | "\n", 85 | "print quicksort([3,6,8,10,1,2,1])" 86 | ], 87 | "language": "python", 88 | "metadata": {}, 89 | "outputs": [ 90 | { 91 | "output_type": "stream", 92 | "stream": "stdout", 93 | "text": [ 94 | "[1, 1, 2, 3, 6, 8, 10]\n" 95 | ] 96 | } 97 | ], 98 | "prompt_number": 1 99 | }, 100 | { 101 | "cell_type": "heading", 102 | "level": 3, 103 | "metadata": {}, 104 | "source": [ 105 | "Python versions" 106 | ] 107 | }, 108 | { 109 | "cell_type": "markdown", 110 | "metadata": {}, 111 | "source": [ 112 | "There are currently two different supported versions of Python, 2.7 and 3.4. Somewhat confusingly, Python 3.0 introduced many backwards-incompatible changes to the language, so code written for 2.7 may not work under 3.4 and vice versa. For this class all code will use Python 2.7.\n", 113 | "\n", 114 | "You can check your Python version at the command line by running `python --version`." 115 | ] 116 | }, 117 | { 118 | "cell_type": "heading", 119 | "level": 3, 120 | "metadata": {}, 121 | "source": [ 122 | "Basic data types" 123 | ] 124 | }, 125 | { 126 | "cell_type": "heading", 127 | "level": 4, 128 | "metadata": {}, 129 | "source": [ 130 | "Numbers" 131 | ] 132 | }, 133 | { 134 | "cell_type": "markdown", 135 | "metadata": {}, 136 | "source": [ 137 | "Integers and floats work as you would expect from other languages:" 138 | ] 139 | }, 140 | { 141 | "cell_type": "code", 142 | "collapsed": false, 143 | "input": [ 144 | "x = 3\n", 145 | "print x, type(x)" 146 | ], 147 | "language": "python", 148 | "metadata": {}, 149 | "outputs": [ 150 | { 151 | "output_type": "stream", 152 | "stream": "stdout", 153 | "text": [ 154 | "3 \n" 155 | ] 156 | } 157 | ], 158 | "prompt_number": 13 159 | }, 160 | { 161 | "cell_type": "code", 162 | "collapsed": false, 163 | "input": [ 164 | "print x + 1 # Addition;\n", 165 | "print x - 1 # Subtraction;\n", 166 | "print x * 2 # Multiplication;\n", 167 | "print x ** 2 # Exponentiation;" 168 | ], 169 | "language": "python", 170 | "metadata": {}, 171 | "outputs": [ 172 | { 173 | "output_type": "stream", 174 | "stream": "stdout", 175 | "text": [ 176 | "4\n", 177 | "2\n", 178 | "6\n", 179 | "9\n" 180 | ] 181 | } 182 | ], 183 | "prompt_number": 15 184 | }, 185 | { 186 | "cell_type": "code", 187 | "collapsed": false, 188 | "input": [ 189 | "x += 1\n", 190 | "print x # Prints \"4\"\n", 191 | "x *= 2\n", 192 | "print x # Prints \"8\"" 193 | ], 194 | "language": "python", 195 | "metadata": {}, 196 | "outputs": [ 197 | { 198 | "output_type": "stream", 199 | "stream": "stdout", 200 | "text": [ 201 | "4\n", 202 | "8\n" 203 | ] 204 | } 205 | ], 206 | "prompt_number": 16 207 | }, 208 | { 209 | "cell_type": "code", 210 | "collapsed": false, 211 | "input": [ 212 | "y = 2.5\n", 213 | "print type(y) # Prints \"\"\n", 214 | "print y, y + 1, y * 2, y ** 2 # Prints \"2.5 3.5 5.0 6.25\"" 215 | ], 216 | "language": "python", 217 | "metadata": {}, 218 | "outputs": [ 219 | { 220 | "output_type": "stream", 221 | "stream": "stdout", 222 | "text": [ 223 | "\n", 224 | "2.5 3.5 5.0 6.25\n" 225 | ] 226 | } 227 | ], 228 | "prompt_number": 17 229 | }, 230 | { 231 | "cell_type": "markdown", 232 | "metadata": {}, 233 | "source": [ 234 | "Note that unlike many languages, Python does not have unary increment (x++) or decrement (x--) operators.\n", 235 | "\n", 236 | "Python also has built-in types for long integers and complex numbers; you can find all of the details in the [documentation](https://docs.python.org/2/library/stdtypes.html#numeric-types-int-float-long-complex)." 237 | ] 238 | }, 239 | { 240 | "cell_type": "heading", 241 | "level": 4, 242 | "metadata": {}, 243 | "source": [ 244 | "Booleans" 245 | ] 246 | }, 247 | { 248 | "cell_type": "markdown", 249 | "metadata": {}, 250 | "source": [ 251 | "Python implements all of the usual operators for Boolean logic, but uses English words rather than symbols (`&&`, `||`, etc.):" 252 | ] 253 | }, 254 | { 255 | "cell_type": "code", 256 | "collapsed": false, 257 | "input": [ 258 | "t, f = True, False\n", 259 | "print type(t) # Prints \"\"" 260 | ], 261 | "language": "python", 262 | "metadata": {}, 263 | "outputs": [ 264 | { 265 | "output_type": "stream", 266 | "stream": "stdout", 267 | "text": [ 268 | "\n" 269 | ] 270 | } 271 | ], 272 | "prompt_number": 139 273 | }, 274 | { 275 | "cell_type": "markdown", 276 | "metadata": {}, 277 | "source": [ 278 | "Now we let's look at the operations:" 279 | ] 280 | }, 281 | { 282 | "cell_type": "code", 283 | "collapsed": false, 284 | "input": [ 285 | "print t and f # Logical AND;\n", 286 | "print t or f # Logical OR;\n", 287 | "print not t # Logical NOT;\n", 288 | "print t != f # Logical XOR;" 289 | ], 290 | "language": "python", 291 | "metadata": {}, 292 | "outputs": [ 293 | { 294 | "output_type": "stream", 295 | "stream": "stdout", 296 | "text": [ 297 | "False\n", 298 | "True\n", 299 | "False\n", 300 | "True\n" 301 | ] 302 | } 303 | ], 304 | "prompt_number": 140 305 | }, 306 | { 307 | "cell_type": "heading", 308 | "level": 4, 309 | "metadata": {}, 310 | "source": [ 311 | "Strings" 312 | ] 313 | }, 314 | { 315 | "cell_type": "code", 316 | "collapsed": false, 317 | "input": [ 318 | "hello = 'hello' # String literals can use single quotes\n", 319 | "world = \"world\" # or double quotes; it does not matter.\n", 320 | "print hello, len(hello)" 321 | ], 322 | "language": "python", 323 | "metadata": {}, 324 | "outputs": [ 325 | { 326 | "output_type": "stream", 327 | "stream": "stdout", 328 | "text": [ 329 | "hello 5\n" 330 | ] 331 | } 332 | ], 333 | "prompt_number": 142 334 | }, 335 | { 336 | "cell_type": "code", 337 | "collapsed": false, 338 | "input": [ 339 | "hw = hello + ' ' + world # String concatenation\n", 340 | "print hw # prints \"hello world\"" 341 | ], 342 | "language": "python", 343 | "metadata": {}, 344 | "outputs": [ 345 | { 346 | "output_type": "stream", 347 | "stream": "stdout", 348 | "text": [ 349 | "hello world\n" 350 | ] 351 | } 352 | ], 353 | "prompt_number": 143 354 | }, 355 | { 356 | "cell_type": "code", 357 | "collapsed": false, 358 | "input": [ 359 | "hw12 = '%s %s %d' % (hello, world, 12) # sprintf style string formatting\n", 360 | "print hw12 # prints \"hello world 12\"" 361 | ], 362 | "language": "python", 363 | "metadata": {}, 364 | "outputs": [ 365 | { 366 | "output_type": "stream", 367 | "stream": "stdout", 368 | "text": [ 369 | "hello world 12\n" 370 | ] 371 | } 372 | ], 373 | "prompt_number": 144 374 | }, 375 | { 376 | "cell_type": "markdown", 377 | "metadata": {}, 378 | "source": [ 379 | "String objects have a bunch of useful methods; for example:" 380 | ] 381 | }, 382 | { 383 | "cell_type": "code", 384 | "collapsed": false, 385 | "input": [ 386 | "s = \"hello\"\n", 387 | "print s.capitalize() # Capitalize a string; prints \"Hello\"\n", 388 | "print s.upper() # Convert a string to uppercase; prints \"HELLO\"\n", 389 | "print s.rjust(7) # Right-justify a string, padding with spaces; prints \" hello\"\n", 390 | "print s.center(7) # Center a string, padding with spaces; prints \" hello \"\n", 391 | "print s.replace('l', '(ell)') # Replace all instances of one substring with another;\n", 392 | " # prints \"he(ell)(ell)o\"\n", 393 | "print ' world '.strip() # Strip leading and trailing whitespace; prints \"world\"" 394 | ], 395 | "language": "python", 396 | "metadata": {}, 397 | "outputs": [ 398 | { 399 | "output_type": "stream", 400 | "stream": "stdout", 401 | "text": [ 402 | "Hello\n", 403 | "HELLO\n", 404 | " hello\n", 405 | " hello \n", 406 | "he(ell)(ell)o\n", 407 | "world\n" 408 | ] 409 | } 410 | ], 411 | "prompt_number": 26 412 | }, 413 | { 414 | "cell_type": "markdown", 415 | "metadata": {}, 416 | "source": [ 417 | "You can find a list of all string methods in the [documentation](https://docs.python.org/2/library/stdtypes.html#string-methods)." 418 | ] 419 | }, 420 | { 421 | "cell_type": "heading", 422 | "level": 3, 423 | "metadata": {}, 424 | "source": [ 425 | "Containers" 426 | ] 427 | }, 428 | { 429 | "cell_type": "markdown", 430 | "metadata": {}, 431 | "source": [ 432 | "Python includes several built-in container types: lists, dictionaries, sets, and tuples." 433 | ] 434 | }, 435 | { 436 | "cell_type": "heading", 437 | "level": 4, 438 | "metadata": {}, 439 | "source": [ 440 | "Lists" 441 | ] 442 | }, 443 | { 444 | "cell_type": "markdown", 445 | "metadata": {}, 446 | "source": [ 447 | "A list is the Python equivalent of an array, but is resizeable and can contain elements of different types:" 448 | ] 449 | }, 450 | { 451 | "cell_type": "code", 452 | "collapsed": false, 453 | "input": [ 454 | "xs = [3, 1, 2] # Create a list\n", 455 | "print xs, xs[2]\n", 456 | "print xs[-1] # Negative indices count from the end of the list; prints \"2\"" 457 | ], 458 | "language": "python", 459 | "metadata": {}, 460 | "outputs": [ 461 | { 462 | "output_type": "stream", 463 | "stream": "stdout", 464 | "text": [ 465 | "[3, 1, 2] 2\n", 466 | "2\n" 467 | ] 468 | } 469 | ], 470 | "prompt_number": 146 471 | }, 472 | { 473 | "cell_type": "code", 474 | "collapsed": false, 475 | "input": [ 476 | "xs[2] = 'foo' # Lists can contain elements of different types\n", 477 | "print xs" 478 | ], 479 | "language": "python", 480 | "metadata": {}, 481 | "outputs": [ 482 | { 483 | "output_type": "stream", 484 | "stream": "stdout", 485 | "text": [ 486 | "[3, 1, 'foo']\n" 487 | ] 488 | } 489 | ], 490 | "prompt_number": 148 491 | }, 492 | { 493 | "cell_type": "code", 494 | "collapsed": false, 495 | "input": [ 496 | "xs.append('bar') # Add a new element to the end of the list\n", 497 | "print xs " 498 | ], 499 | "language": "python", 500 | "metadata": {}, 501 | "outputs": [ 502 | { 503 | "output_type": "stream", 504 | "stream": "stdout", 505 | "text": [ 506 | "[3, 1, 'foo', 'bar']\n" 507 | ] 508 | } 509 | ], 510 | "prompt_number": 150 511 | }, 512 | { 513 | "cell_type": "code", 514 | "collapsed": false, 515 | "input": [ 516 | "x = xs.pop() # Remove and return the last element of the list\n", 517 | "print x, xs " 518 | ], 519 | "language": "python", 520 | "metadata": {}, 521 | "outputs": [ 522 | { 523 | "output_type": "stream", 524 | "stream": "stdout", 525 | "text": [ 526 | "bar [3, 1, 'foo']\n" 527 | ] 528 | } 529 | ], 530 | "prompt_number": 152 531 | }, 532 | { 533 | "cell_type": "markdown", 534 | "metadata": {}, 535 | "source": [ 536 | "As usual, you can find all the gory details about lists in the [documentation](https://docs.python.org/2/tutorial/datastructures.html#more-on-lists)." 537 | ] 538 | }, 539 | { 540 | "cell_type": "heading", 541 | "level": 4, 542 | "metadata": {}, 543 | "source": [ 544 | "Slicing" 545 | ] 546 | }, 547 | { 548 | "cell_type": "markdown", 549 | "metadata": {}, 550 | "source": [ 551 | "In addition to accessing list elements one at a time, Python provides concise syntax to access sublists; this is known as slicing:" 552 | ] 553 | }, 554 | { 555 | "cell_type": "code", 556 | "collapsed": false, 557 | "input": [ 558 | "nums = range(5) # range is a built-in function that creates a list of integers\n", 559 | "print nums # Prints \"[0, 1, 2, 3, 4]\"\n", 560 | "print nums[2:4] # Get a slice from index 2 to 4 (exclusive); prints \"[2, 3]\"\n", 561 | "print nums[2:] # Get a slice from index 2 to the end; prints \"[2, 3, 4]\"\n", 562 | "print nums[:2] # Get a slice from the start to index 2 (exclusive); prints \"[0, 1]\"\n", 563 | "print nums[:] # Get a slice of the whole list; prints [\"0, 1, 2, 3, 4]\"\n", 564 | "print nums[:-1] # Slice indices can be negative; prints [\"0, 1, 2, 3]\"\n", 565 | "nums[2:4] = [8, 9] # Assign a new sublist to a slice\n", 566 | "print nums # Prints \"[0, 1, 8, 9, 4]\"" 567 | ], 568 | "language": "python", 569 | "metadata": {}, 570 | "outputs": [ 571 | { 572 | "output_type": "stream", 573 | "stream": "stdout", 574 | "text": [ 575 | "[0, 1, 2, 3, 4]\n", 576 | "[2, 3]\n", 577 | "[2, 3, 4]\n", 578 | "[0, 1]\n", 579 | "[0, 1, 2, 3, 4]\n", 580 | "[0, 1, 2, 3]\n", 581 | "[0, 1, 8, 9, 4]\n" 582 | ] 583 | } 584 | ], 585 | "prompt_number": 36 586 | }, 587 | { 588 | "cell_type": "heading", 589 | "level": 4, 590 | "metadata": {}, 591 | "source": [ 592 | "Loops" 593 | ] 594 | }, 595 | { 596 | "cell_type": "markdown", 597 | "metadata": {}, 598 | "source": [ 599 | "You can loop over the elements of a list like this:" 600 | ] 601 | }, 602 | { 603 | "cell_type": "code", 604 | "collapsed": false, 605 | "input": [ 606 | "animals = ['cat', 'dog', 'monkey']\n", 607 | "for animal in animals:\n", 608 | " print animal" 609 | ], 610 | "language": "python", 611 | "metadata": {}, 612 | "outputs": [ 613 | { 614 | "output_type": "stream", 615 | "stream": "stdout", 616 | "text": [ 617 | "cat\n", 618 | "dog\n", 619 | "monkey\n" 620 | ] 621 | } 622 | ], 623 | "prompt_number": 153 624 | }, 625 | { 626 | "cell_type": "markdown", 627 | "metadata": {}, 628 | "source": [ 629 | "If you want access to the index of each element within the body of a loop, use the built-in `enumerate` function:" 630 | ] 631 | }, 632 | { 633 | "cell_type": "code", 634 | "collapsed": false, 635 | "input": [ 636 | "animals = ['cat', 'dog', 'monkey']\n", 637 | "for idx, animal in enumerate(animals):\n", 638 | " print '#%d: %s' % (idx + 1, animal)" 639 | ], 640 | "language": "python", 641 | "metadata": {}, 642 | "outputs": [ 643 | { 644 | "output_type": "stream", 645 | "stream": "stdout", 646 | "text": [ 647 | "#1: cat\n", 648 | "#2: dog\n", 649 | "#3: monkey\n" 650 | ] 651 | } 652 | ], 653 | "prompt_number": 154 654 | }, 655 | { 656 | "cell_type": "heading", 657 | "level": 4, 658 | "metadata": {}, 659 | "source": [ 660 | "List comprehensions:" 661 | ] 662 | }, 663 | { 664 | "cell_type": "markdown", 665 | "metadata": {}, 666 | "source": [ 667 | "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:" 668 | ] 669 | }, 670 | { 671 | "cell_type": "code", 672 | "collapsed": false, 673 | "input": [ 674 | "nums = [0, 1, 2, 3, 4]\n", 675 | "squares = []\n", 676 | "for x in nums:\n", 677 | " squares.append(x ** 2)\n", 678 | "print squares" 679 | ], 680 | "language": "python", 681 | "metadata": {}, 682 | "outputs": [ 683 | { 684 | "output_type": "stream", 685 | "stream": "stdout", 686 | "text": [ 687 | "[0, 1, 4, 9, 16]\n" 688 | ] 689 | } 690 | ], 691 | "prompt_number": 155 692 | }, 693 | { 694 | "cell_type": "markdown", 695 | "metadata": {}, 696 | "source": [ 697 | "You can make this code simpler using a list comprehension:" 698 | ] 699 | }, 700 | { 701 | "cell_type": "code", 702 | "collapsed": false, 703 | "input": [ 704 | "nums = [0, 1, 2, 3, 4]\n", 705 | "squares = [x ** 2 for x in nums]\n", 706 | "print squares" 707 | ], 708 | "language": "python", 709 | "metadata": {}, 710 | "outputs": [ 711 | { 712 | "output_type": "stream", 713 | "stream": "stdout", 714 | "text": [ 715 | "[0, 1, 4, 9, 16]\n" 716 | ] 717 | } 718 | ], 719 | "prompt_number": 156 720 | }, 721 | { 722 | "cell_type": "markdown", 723 | "metadata": {}, 724 | "source": [ 725 | "List comprehensions can also contain conditions:" 726 | ] 727 | }, 728 | { 729 | "cell_type": "code", 730 | "collapsed": false, 731 | "input": [ 732 | "nums = [0, 1, 2, 3, 4]\n", 733 | "even_squares = [x ** 2 for x in nums if x % 2 == 0]\n", 734 | "print even_squares" 735 | ], 736 | "language": "python", 737 | "metadata": {}, 738 | "outputs": [ 739 | { 740 | "output_type": "stream", 741 | "stream": "stdout", 742 | "text": [ 743 | "[0, 4, 16]\n" 744 | ] 745 | } 746 | ], 747 | "prompt_number": 157 748 | }, 749 | { 750 | "cell_type": "heading", 751 | "level": 4, 752 | "metadata": {}, 753 | "source": [ 754 | "Dictionaries" 755 | ] 756 | }, 757 | { 758 | "cell_type": "markdown", 759 | "metadata": {}, 760 | "source": [ 761 | "A dictionary stores (key, value) pairs, similar to a `Map` in Java or an object in Javascript. You can use it like this:" 762 | ] 763 | }, 764 | { 765 | "cell_type": "code", 766 | "collapsed": false, 767 | "input": [ 768 | "d = {'cat': 'cute', 'dog': 'furry'} # Create a new dictionary with some data\n", 769 | "print d['cat'] # Get an entry from a dictionary; prints \"cute\"\n", 770 | "print 'cat' in d # Check if a dictionary has a given key; prints \"True\"" 771 | ], 772 | "language": "python", 773 | "metadata": {}, 774 | "outputs": [ 775 | { 776 | "output_type": "stream", 777 | "stream": "stdout", 778 | "text": [ 779 | "cute\n", 780 | "True\n" 781 | ] 782 | } 783 | ], 784 | "prompt_number": 158 785 | }, 786 | { 787 | "cell_type": "code", 788 | "collapsed": false, 789 | "input": [ 790 | "d['fish'] = 'wet' # Set an entry in a dictionary\n", 791 | "print d['fish'] # Prints \"wet\"" 792 | ], 793 | "language": "python", 794 | "metadata": {}, 795 | "outputs": [ 796 | { 797 | "output_type": "stream", 798 | "stream": "stdout", 799 | "text": [ 800 | "wet\n" 801 | ] 802 | } 803 | ], 804 | "prompt_number": 159 805 | }, 806 | { 807 | "cell_type": "code", 808 | "collapsed": false, 809 | "input": [ 810 | "print d['monkey'] # KeyError: 'monkey' not a key of d" 811 | ], 812 | "language": "python", 813 | "metadata": {}, 814 | "outputs": [ 815 | { 816 | "ename": "KeyError", 817 | "evalue": "'monkey'", 818 | "output_type": "pyerr", 819 | "traceback": [ 820 | "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[0;31mKeyError\u001b[0m Traceback (most recent call last)", 821 | "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0;32mprint\u001b[0m \u001b[0md\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'monkey'\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;31m# KeyError: 'monkey' not a key of d\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", 822 | "\u001b[0;31mKeyError\u001b[0m: 'monkey'" 823 | ] 824 | } 825 | ], 826 | "prompt_number": 161 827 | }, 828 | { 829 | "cell_type": "code", 830 | "collapsed": false, 831 | "input": [ 832 | "print d.get('monkey', 'N/A') # Get an element with a default; prints \"N/A\"\n", 833 | "print d.get('fish', 'N/A') # Get an element with a default; prints \"wet\"" 834 | ], 835 | "language": "python", 836 | "metadata": {}, 837 | "outputs": [ 838 | { 839 | "output_type": "stream", 840 | "stream": "stdout", 841 | "text": [ 842 | "N/A\n", 843 | "wet\n" 844 | ] 845 | } 846 | ], 847 | "prompt_number": 162 848 | }, 849 | { 850 | "cell_type": "code", 851 | "collapsed": false, 852 | "input": [ 853 | "del d['fish'] # Remove an element from a dictionary\n", 854 | "print d.get('fish', 'N/A') # \"fish\" is no longer a key; prints \"N/A\"" 855 | ], 856 | "language": "python", 857 | "metadata": {}, 858 | "outputs": [ 859 | { 860 | "output_type": "stream", 861 | "stream": "stdout", 862 | "text": [ 863 | "N/A\n" 864 | ] 865 | } 866 | ], 867 | "prompt_number": 163 868 | }, 869 | { 870 | "cell_type": "markdown", 871 | "metadata": {}, 872 | "source": [ 873 | "You can find all you need to know about dictionaries in the [documentation](https://docs.python.org/2/library/stdtypes.html#dict)." 874 | ] 875 | }, 876 | { 877 | "cell_type": "markdown", 878 | "metadata": {}, 879 | "source": [ 880 | "It is easy to iterate over the keys in a dictionary:" 881 | ] 882 | }, 883 | { 884 | "cell_type": "code", 885 | "collapsed": false, 886 | "input": [ 887 | "d = {'person': 2, 'cat': 4, 'spider': 8}\n", 888 | "for animal in d:\n", 889 | " legs = d[animal]\n", 890 | " print 'A %s has %d legs' % (animal, legs)" 891 | ], 892 | "language": "python", 893 | "metadata": {}, 894 | "outputs": [ 895 | { 896 | "output_type": "stream", 897 | "stream": "stdout", 898 | "text": [ 899 | "A person has 2 legs\n", 900 | "A spider has 8 legs\n", 901 | "A cat has 4 legs\n" 902 | ] 903 | } 904 | ], 905 | "prompt_number": 164 906 | }, 907 | { 908 | "cell_type": "markdown", 909 | "metadata": {}, 910 | "source": [ 911 | "If you want access to keys and their corresponding values, use the iteritems method:" 912 | ] 913 | }, 914 | { 915 | "cell_type": "code", 916 | "collapsed": false, 917 | "input": [ 918 | "d = {'person': 2, 'cat': 4, 'spider': 8}\n", 919 | "for animal, legs in d.iteritems():\n", 920 | " print 'A %s has %d legs' % (animal, legs)" 921 | ], 922 | "language": "python", 923 | "metadata": {}, 924 | "outputs": [ 925 | { 926 | "output_type": "stream", 927 | "stream": "stdout", 928 | "text": [ 929 | "A person has 2 legs\n", 930 | "A spider has 8 legs\n", 931 | "A cat has 4 legs\n" 932 | ] 933 | } 934 | ], 935 | "prompt_number": 165 936 | }, 937 | { 938 | "cell_type": "markdown", 939 | "metadata": {}, 940 | "source": [ 941 | "Dictionary comprehensions: These are similar to list comprehensions, but allow you to easily construct dictionaries. For example:" 942 | ] 943 | }, 944 | { 945 | "cell_type": "code", 946 | "collapsed": false, 947 | "input": [ 948 | "nums = [0, 1, 2, 3, 4]\n", 949 | "even_num_to_square = {x: x ** 2 for x in nums if x % 2 == 0}\n", 950 | "print even_num_to_square" 951 | ], 952 | "language": "python", 953 | "metadata": {}, 954 | "outputs": [ 955 | { 956 | "output_type": "stream", 957 | "stream": "stdout", 958 | "text": [ 959 | "{0: 0, 2: 4, 4: 16}\n" 960 | ] 961 | } 962 | ], 963 | "prompt_number": 166 964 | }, 965 | { 966 | "cell_type": "heading", 967 | "level": 4, 968 | "metadata": {}, 969 | "source": [ 970 | "Sets" 971 | ] 972 | }, 973 | { 974 | "cell_type": "markdown", 975 | "metadata": {}, 976 | "source": [ 977 | "A set is an unordered collection of distinct elements. As a simple example, consider the following:" 978 | ] 979 | }, 980 | { 981 | "cell_type": "code", 982 | "collapsed": false, 983 | "input": [ 984 | "animals = {'cat', 'dog'}\n", 985 | "print 'cat' in animals # Check if an element is in a set; prints \"True\"\n", 986 | "print 'fish' in animals # prints \"False\"\n" 987 | ], 988 | "language": "python", 989 | "metadata": {}, 990 | "outputs": [ 991 | { 992 | "output_type": "stream", 993 | "stream": "stdout", 994 | "text": [ 995 | "True\n", 996 | "False\n" 997 | ] 998 | } 999 | ], 1000 | "prompt_number": 167 1001 | }, 1002 | { 1003 | "cell_type": "code", 1004 | "collapsed": false, 1005 | "input": [ 1006 | "animals.add('fish') # Add an element to a set\n", 1007 | "print 'fish' in animals\n", 1008 | "print len(animals) # Number of elements in a set;" 1009 | ], 1010 | "language": "python", 1011 | "metadata": {}, 1012 | "outputs": [ 1013 | { 1014 | "output_type": "stream", 1015 | "stream": "stdout", 1016 | "text": [ 1017 | "True\n", 1018 | "3\n" 1019 | ] 1020 | } 1021 | ], 1022 | "prompt_number": 170 1023 | }, 1024 | { 1025 | "cell_type": "code", 1026 | "collapsed": false, 1027 | "input": [ 1028 | "animals.add('cat') # Adding an element that is already in the set does nothing\n", 1029 | "print len(animals) \n", 1030 | "animals.remove('cat') # Remove an element from a set\n", 1031 | "print len(animals) " 1032 | ], 1033 | "language": "python", 1034 | "metadata": {}, 1035 | "outputs": [ 1036 | { 1037 | "output_type": "stream", 1038 | "stream": "stdout", 1039 | "text": [ 1040 | "3\n", 1041 | "2\n" 1042 | ] 1043 | } 1044 | ], 1045 | "prompt_number": 171 1046 | }, 1047 | { 1048 | "cell_type": "markdown", 1049 | "metadata": {}, 1050 | "source": [ 1051 | "_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:" 1052 | ] 1053 | }, 1054 | { 1055 | "cell_type": "code", 1056 | "collapsed": false, 1057 | "input": [ 1058 | "animals = {'cat', 'dog', 'fish'}\n", 1059 | "for idx, animal in enumerate(animals):\n", 1060 | " print '#%d: %s' % (idx + 1, animal)\n", 1061 | "# Prints \"#1: fish\", \"#2: dog\", \"#3: cat\"" 1062 | ], 1063 | "language": "python", 1064 | "metadata": {}, 1065 | "outputs": [ 1066 | { 1067 | "output_type": "stream", 1068 | "stream": "stdout", 1069 | "text": [ 1070 | "#1: fish\n", 1071 | "#2: dog\n", 1072 | "#3: cat\n" 1073 | ] 1074 | } 1075 | ], 1076 | "prompt_number": 63 1077 | }, 1078 | { 1079 | "cell_type": "markdown", 1080 | "metadata": {}, 1081 | "source": [ 1082 | "Set comprehensions: Like lists and dictionaries, we can easily construct sets using set comprehensions:" 1083 | ] 1084 | }, 1085 | { 1086 | "cell_type": "code", 1087 | "collapsed": false, 1088 | "input": [ 1089 | "from math import sqrt\n", 1090 | "print {int(sqrt(x)) for x in range(30)}" 1091 | ], 1092 | "language": "python", 1093 | "metadata": {}, 1094 | "outputs": [ 1095 | { 1096 | "output_type": "stream", 1097 | "stream": "stdout", 1098 | "text": [ 1099 | "set([0, 1, 2, 3, 4, 5])\n" 1100 | ] 1101 | } 1102 | ], 1103 | "prompt_number": 172 1104 | }, 1105 | { 1106 | "cell_type": "heading", 1107 | "level": 4, 1108 | "metadata": {}, 1109 | "source": [ 1110 | "Tuples" 1111 | ] 1112 | }, 1113 | { 1114 | "cell_type": "markdown", 1115 | "metadata": {}, 1116 | "source": [ 1117 | "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:" 1118 | ] 1119 | }, 1120 | { 1121 | "cell_type": "code", 1122 | "collapsed": false, 1123 | "input": [ 1124 | "d = {(x, x + 1): x for x in range(10)} # Create a dictionary with tuple keys\n", 1125 | "t = (5, 6) # Create a tuple\n", 1126 | "print type(t)\n", 1127 | "print d[t] \n", 1128 | "print d[(1, 2)]" 1129 | ], 1130 | "language": "python", 1131 | "metadata": {}, 1132 | "outputs": [ 1133 | { 1134 | "output_type": "stream", 1135 | "stream": "stdout", 1136 | "text": [ 1137 | "\n", 1138 | "5\n", 1139 | "1\n" 1140 | ] 1141 | } 1142 | ], 1143 | "prompt_number": 173 1144 | }, 1145 | { 1146 | "cell_type": "code", 1147 | "collapsed": false, 1148 | "input": [ 1149 | "t[0] = 1" 1150 | ], 1151 | "language": "python", 1152 | "metadata": {}, 1153 | "outputs": [ 1154 | { 1155 | "ename": "TypeError", 1156 | "evalue": "'tuple' object does not support item assignment", 1157 | "output_type": "pyerr", 1158 | "traceback": [ 1159 | "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", 1160 | "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mt\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;36m1\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", 1161 | "\u001b[0;31mTypeError\u001b[0m: 'tuple' object does not support item assignment" 1162 | ] 1163 | } 1164 | ], 1165 | "prompt_number": 176 1166 | }, 1167 | { 1168 | "cell_type": "heading", 1169 | "level": 3, 1170 | "metadata": {}, 1171 | "source": [ 1172 | "Functions" 1173 | ] 1174 | }, 1175 | { 1176 | "cell_type": "markdown", 1177 | "metadata": {}, 1178 | "source": [ 1179 | "Python functions are defined using the `def` keyword. For example:" 1180 | ] 1181 | }, 1182 | { 1183 | "cell_type": "code", 1184 | "collapsed": false, 1185 | "input": [ 1186 | "def sign(x):\n", 1187 | " if x > 0:\n", 1188 | " return 'positive'\n", 1189 | " elif x < 0:\n", 1190 | " return 'negative'\n", 1191 | " else:\n", 1192 | " return 'zero'\n", 1193 | "\n", 1194 | "for x in [-1, 0, 1]:\n", 1195 | " print sign(x)" 1196 | ], 1197 | "language": "python", 1198 | "metadata": {}, 1199 | "outputs": [ 1200 | { 1201 | "output_type": "stream", 1202 | "stream": "stdout", 1203 | "text": [ 1204 | "negative\n", 1205 | "zero\n", 1206 | "positive\n" 1207 | ] 1208 | } 1209 | ], 1210 | "prompt_number": 178 1211 | }, 1212 | { 1213 | "cell_type": "markdown", 1214 | "metadata": {}, 1215 | "source": [ 1216 | "We will often define functions to take optional keyword arguments, like this:" 1217 | ] 1218 | }, 1219 | { 1220 | "cell_type": "code", 1221 | "collapsed": false, 1222 | "input": [ 1223 | "def hello(name, loud=False):\n", 1224 | " if loud:\n", 1225 | " print 'HELLO, %s' % name.upper()\n", 1226 | " else:\n", 1227 | " print 'Hello, %s!' % name\n", 1228 | "\n", 1229 | "hello('Bob')\n", 1230 | "hello('Fred', loud=True)" 1231 | ], 1232 | "language": "python", 1233 | "metadata": {}, 1234 | "outputs": [ 1235 | { 1236 | "output_type": "stream", 1237 | "stream": "stdout", 1238 | "text": [ 1239 | "Hello, Bob!\n", 1240 | "HELLO, FRED\n" 1241 | ] 1242 | } 1243 | ], 1244 | "prompt_number": 179 1245 | }, 1246 | { 1247 | "cell_type": "heading", 1248 | "level": 3, 1249 | "metadata": {}, 1250 | "source": [ 1251 | "Classes" 1252 | ] 1253 | }, 1254 | { 1255 | "cell_type": "markdown", 1256 | "metadata": {}, 1257 | "source": [ 1258 | "The syntax for defining classes in Python is straightforward:" 1259 | ] 1260 | }, 1261 | { 1262 | "cell_type": "code", 1263 | "collapsed": false, 1264 | "input": [ 1265 | "class Greeter:\n", 1266 | "\n", 1267 | " # Constructor\n", 1268 | " def __init__(self, name):\n", 1269 | " self.name = name # Create an instance variable\n", 1270 | "\n", 1271 | " # Instance method\n", 1272 | " def greet(self, loud=False):\n", 1273 | " if loud:\n", 1274 | " print 'HELLO, %s!' % self.name.upper()\n", 1275 | " else:\n", 1276 | " print 'Hello, %s' % self.name\n", 1277 | "\n", 1278 | "g = Greeter('Fred') # Construct an instance of the Greeter class\n", 1279 | "g.greet() # Call an instance method; prints \"Hello, Fred\"\n", 1280 | "g.greet(loud=True) # Call an instance method; prints \"HELLO, FRED!\"" 1281 | ], 1282 | "language": "python", 1283 | "metadata": {}, 1284 | "outputs": [ 1285 | { 1286 | "output_type": "stream", 1287 | "stream": "stdout", 1288 | "text": [ 1289 | "Hello, Fred\n", 1290 | "HELLO, FRED!\n" 1291 | ] 1292 | } 1293 | ], 1294 | "prompt_number": 76 1295 | }, 1296 | { 1297 | "cell_type": "heading", 1298 | "level": 2, 1299 | "metadata": {}, 1300 | "source": [ 1301 | "Numpy" 1302 | ] 1303 | }, 1304 | { 1305 | "cell_type": "markdown", 1306 | "metadata": {}, 1307 | "source": [ 1308 | "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. If you are already familiar with MATLAB, you might find this [tutorial](http://wiki.scipy.org/NumPy_for_Matlab_Users) useful to get started with Numpy." 1309 | ] 1310 | }, 1311 | { 1312 | "cell_type": "markdown", 1313 | "metadata": {}, 1314 | "source": [ 1315 | "To use Numpy, we first need to import the `numpy` package:" 1316 | ] 1317 | }, 1318 | { 1319 | "cell_type": "code", 1320 | "collapsed": false, 1321 | "input": [ 1322 | "import numpy as np" 1323 | ], 1324 | "language": "python", 1325 | "metadata": {}, 1326 | "outputs": [], 1327 | "prompt_number": 181 1328 | }, 1329 | { 1330 | "cell_type": "heading", 1331 | "level": 3, 1332 | "metadata": {}, 1333 | "source": [ 1334 | "Arrays" 1335 | ] 1336 | }, 1337 | { 1338 | "cell_type": "markdown", 1339 | "metadata": {}, 1340 | "source": [ 1341 | "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." 1342 | ] 1343 | }, 1344 | { 1345 | "cell_type": "markdown", 1346 | "metadata": {}, 1347 | "source": [ 1348 | "We can initialize numpy arrays from nested Python lists, and access elements using square brackets:" 1349 | ] 1350 | }, 1351 | { 1352 | "cell_type": "code", 1353 | "collapsed": false, 1354 | "input": [ 1355 | "a = np.array([1, 2, 3]) # Create a rank 1 array\n", 1356 | "print type(a), a.shape, a[0], a[1], a[2]\n", 1357 | "a[0] = 5 # Change an element of the array\n", 1358 | "print a " 1359 | ], 1360 | "language": "python", 1361 | "metadata": {}, 1362 | "outputs": [ 1363 | { 1364 | "output_type": "stream", 1365 | "stream": "stdout", 1366 | "text": [ 1367 | " (3,) 1 2 3\n", 1368 | "[5 2 3]\n" 1369 | ] 1370 | } 1371 | ], 1372 | "prompt_number": 196 1373 | }, 1374 | { 1375 | "cell_type": "code", 1376 | "collapsed": false, 1377 | "input": [ 1378 | "b = np.array([[1,2,3],[4,5,6]]) # Create a rank 2 array\n", 1379 | "print b" 1380 | ], 1381 | "language": "python", 1382 | "metadata": {}, 1383 | "outputs": [ 1384 | { 1385 | "output_type": "stream", 1386 | "stream": "stdout", 1387 | "text": [ 1388 | "[[1 2 3]\n", 1389 | " [4 5 6]]\n" 1390 | ] 1391 | } 1392 | ], 1393 | "prompt_number": 198 1394 | }, 1395 | { 1396 | "cell_type": "code", 1397 | "collapsed": false, 1398 | "input": [ 1399 | "print b.shape \n", 1400 | "print b[0, 0], b[0, 1], b[1, 0]" 1401 | ], 1402 | "language": "python", 1403 | "metadata": {}, 1404 | "outputs": [ 1405 | { 1406 | "output_type": "stream", 1407 | "stream": "stdout", 1408 | "text": [ 1409 | "(2, 3)\n", 1410 | "1 2 4\n" 1411 | ] 1412 | } 1413 | ], 1414 | "prompt_number": 199 1415 | }, 1416 | { 1417 | "cell_type": "markdown", 1418 | "metadata": {}, 1419 | "source": [ 1420 | "Numpy also provides many functions to create arrays:" 1421 | ] 1422 | }, 1423 | { 1424 | "cell_type": "code", 1425 | "collapsed": false, 1426 | "input": [ 1427 | "a = np.zeros((2,2)) # Create an array of all zeros\n", 1428 | "print a" 1429 | ], 1430 | "language": "python", 1431 | "metadata": {}, 1432 | "outputs": [ 1433 | { 1434 | "output_type": "stream", 1435 | "stream": "stdout", 1436 | "text": [ 1437 | "[[ 0. 0.]\n", 1438 | " [ 0. 0.]]\n" 1439 | ] 1440 | } 1441 | ], 1442 | "prompt_number": 186 1443 | }, 1444 | { 1445 | "cell_type": "code", 1446 | "collapsed": false, 1447 | "input": [ 1448 | "b = np.ones((1,2)) # Create an array of all ones\n", 1449 | "print b" 1450 | ], 1451 | "language": "python", 1452 | "metadata": {}, 1453 | "outputs": [ 1454 | { 1455 | "output_type": "stream", 1456 | "stream": "stdout", 1457 | "text": [ 1458 | "[[ 1. 1.]]\n" 1459 | ] 1460 | } 1461 | ], 1462 | "prompt_number": 187 1463 | }, 1464 | { 1465 | "cell_type": "code", 1466 | "collapsed": false, 1467 | "input": [ 1468 | "c = np.full((2,2), 7) # Create a constant array\n", 1469 | "print c " 1470 | ], 1471 | "language": "python", 1472 | "metadata": {}, 1473 | "outputs": [ 1474 | { 1475 | "output_type": "stream", 1476 | "stream": "stdout", 1477 | "text": [ 1478 | "[[ 7. 7.]\n", 1479 | " [ 7. 7.]]\n" 1480 | ] 1481 | } 1482 | ], 1483 | "prompt_number": 188 1484 | }, 1485 | { 1486 | "cell_type": "code", 1487 | "collapsed": false, 1488 | "input": [ 1489 | "d = np.eye(2) # Create a 2x2 identity matrix\n", 1490 | "print d" 1491 | ], 1492 | "language": "python", 1493 | "metadata": {}, 1494 | "outputs": [ 1495 | { 1496 | "output_type": "stream", 1497 | "stream": "stdout", 1498 | "text": [ 1499 | "[[ 1. 0.]\n", 1500 | " [ 0. 1.]]\n" 1501 | ] 1502 | } 1503 | ], 1504 | "prompt_number": 190 1505 | }, 1506 | { 1507 | "cell_type": "code", 1508 | "collapsed": false, 1509 | "input": [ 1510 | "e = np.random.random((2,2)) # Create an array filled with random values\n", 1511 | "print e" 1512 | ], 1513 | "language": "python", 1514 | "metadata": {}, 1515 | "outputs": [ 1516 | { 1517 | "output_type": "stream", 1518 | "stream": "stdout", 1519 | "text": [ 1520 | "[[ 0.09477679 0.79267634]\n", 1521 | " [ 0.78291274 0.38962829]]\n" 1522 | ] 1523 | } 1524 | ], 1525 | "prompt_number": 192 1526 | }, 1527 | { 1528 | "cell_type": "heading", 1529 | "level": 3, 1530 | "metadata": {}, 1531 | "source": [ 1532 | "Array indexing" 1533 | ] 1534 | }, 1535 | { 1536 | "cell_type": "markdown", 1537 | "metadata": {}, 1538 | "source": [ 1539 | "Numpy offers several ways to index into arrays." 1540 | ] 1541 | }, 1542 | { 1543 | "cell_type": "markdown", 1544 | "metadata": {}, 1545 | "source": [ 1546 | "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:" 1547 | ] 1548 | }, 1549 | { 1550 | "cell_type": "code", 1551 | "collapsed": false, 1552 | "input": [ 1553 | "import numpy as np\n", 1554 | "\n", 1555 | "# Create the following rank 2 array with shape (3, 4)\n", 1556 | "# [[ 1 2 3 4]\n", 1557 | "# [ 5 6 7 8]\n", 1558 | "# [ 9 10 11 12]]\n", 1559 | "a = np.array([[1,2,3,4], [5,6,7,8], [9,10,11,12]])\n", 1560 | "\n", 1561 | "# Use slicing to pull out the subarray consisting of the first 2 rows\n", 1562 | "# and columns 1 and 2; b is the following array of shape (2, 2):\n", 1563 | "# [[2 3]\n", 1564 | "# [6 7]]\n", 1565 | "b = a[:2, 1:3]\n", 1566 | "print b" 1567 | ], 1568 | "language": "python", 1569 | "metadata": {}, 1570 | "outputs": [ 1571 | { 1572 | "output_type": "stream", 1573 | "stream": "stdout", 1574 | "text": [ 1575 | "[[2 3]\n", 1576 | " [6 7]]\n" 1577 | ] 1578 | } 1579 | ], 1580 | "prompt_number": 203 1581 | }, 1582 | { 1583 | "cell_type": "markdown", 1584 | "metadata": {}, 1585 | "source": [ 1586 | "A slice of an array is a view into the same data, so modifying it will modify the original array." 1587 | ] 1588 | }, 1589 | { 1590 | "cell_type": "code", 1591 | "collapsed": false, 1592 | "input": [ 1593 | "print a[0, 1] \n", 1594 | "b[0, 0] = 77 # b[0, 0] is the same piece of data as a[0, 1]\n", 1595 | "print a[0, 1] " 1596 | ], 1597 | "language": "python", 1598 | "metadata": {}, 1599 | "outputs": [ 1600 | { 1601 | "output_type": "stream", 1602 | "stream": "stdout", 1603 | "text": [ 1604 | "2\n", 1605 | "77\n" 1606 | ] 1607 | } 1608 | ], 1609 | "prompt_number": 202 1610 | }, 1611 | { 1612 | "cell_type": "markdown", 1613 | "metadata": {}, 1614 | "source": [ 1615 | "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:" 1616 | ] 1617 | }, 1618 | { 1619 | "cell_type": "code", 1620 | "collapsed": false, 1621 | "input": [ 1622 | "# Create the following rank 2 array with shape (3, 4)\n", 1623 | "a = np.array([[1,2,3,4], [5,6,7,8], [9,10,11,12]])\n", 1624 | "print a" 1625 | ], 1626 | "language": "python", 1627 | "metadata": {}, 1628 | "outputs": [ 1629 | { 1630 | "output_type": "stream", 1631 | "stream": "stdout", 1632 | "text": [ 1633 | "[[ 1 2 3 4]\n", 1634 | " [ 5 6 7 8]\n", 1635 | " [ 9 10 11 12]]\n" 1636 | ] 1637 | } 1638 | ], 1639 | "prompt_number": 209 1640 | }, 1641 | { 1642 | "cell_type": "markdown", 1643 | "metadata": {}, 1644 | "source": [ 1645 | "Two ways of accessing the data in the middle row of the array.\n", 1646 | "Mixing integer indexing with slices yields an array of lower rank,\n", 1647 | "while using only slices yields an array of the same rank as the\n", 1648 | "original array:" 1649 | ] 1650 | }, 1651 | { 1652 | "cell_type": "code", 1653 | "collapsed": false, 1654 | "input": [ 1655 | "row_r1 = a[1, :] # Rank 1 view of the second row of a \n", 1656 | "row_r2 = a[1:2, :] # Rank 2 view of the second row of a\n", 1657 | "row_r3 = a[[1], :] # Rank 2 view of the second row of a\n", 1658 | "print row_r1, row_r1.shape \n", 1659 | "print row_r2, row_r2.shape\n", 1660 | "print row_r3, row_r3.shape" 1661 | ], 1662 | "language": "python", 1663 | "metadata": {}, 1664 | "outputs": [ 1665 | { 1666 | "output_type": "stream", 1667 | "stream": "stdout", 1668 | "text": [ 1669 | "[ 5 6 7 8] (4,)\n", 1670 | "[[ 5 6 7 8]] (1, 4)\n", 1671 | "[[ 5 6 7 8]] (1, 4)\n" 1672 | ] 1673 | } 1674 | ], 1675 | "prompt_number": 219 1676 | }, 1677 | { 1678 | "cell_type": "code", 1679 | "collapsed": false, 1680 | "input": [ 1681 | "# We can make the same distinction when accessing columns of an array:\n", 1682 | "col_r1 = a[:, 1]\n", 1683 | "col_r2 = a[:, 1:2]\n", 1684 | "print col_r1, col_r1.shape\n", 1685 | "print\n", 1686 | "print col_r2, col_r2.shape" 1687 | ], 1688 | "language": "python", 1689 | "metadata": {}, 1690 | "outputs": [ 1691 | { 1692 | "output_type": "stream", 1693 | "stream": "stdout", 1694 | "text": [ 1695 | "[ 2 6 10] (3,)\n", 1696 | "\n", 1697 | "[[ 2]\n", 1698 | " [ 6]\n", 1699 | " [10]] (3, 1)\n" 1700 | ] 1701 | } 1702 | ], 1703 | "prompt_number": 212 1704 | }, 1705 | { 1706 | "cell_type": "markdown", 1707 | "metadata": {}, 1708 | "source": [ 1709 | "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:" 1710 | ] 1711 | }, 1712 | { 1713 | "cell_type": "code", 1714 | "collapsed": false, 1715 | "input": [ 1716 | "a = np.array([[1,2], [3, 4], [5, 6]])\n", 1717 | "\n", 1718 | "# An example of integer array indexing.\n", 1719 | "# The returned array will have shape (3,) and \n", 1720 | "print a[[0, 1, 2], [0, 1, 0]]\n", 1721 | "\n", 1722 | "# The above example of integer array indexing is equivalent to this:\n", 1723 | "print np.array([a[0, 0], a[1, 1], a[2, 0]])" 1724 | ], 1725 | "language": "python", 1726 | "metadata": {}, 1727 | "outputs": [ 1728 | { 1729 | "output_type": "stream", 1730 | "stream": "stdout", 1731 | "text": [ 1732 | "[1 4 5]\n", 1733 | "[1 4 5]\n" 1734 | ] 1735 | } 1736 | ], 1737 | "prompt_number": 220 1738 | }, 1739 | { 1740 | "cell_type": "code", 1741 | "collapsed": false, 1742 | "input": [ 1743 | "# When using integer array indexing, you can reuse the same\n", 1744 | "# element from the source array:\n", 1745 | "print a[[0, 0], [1, 1]]\n", 1746 | "\n", 1747 | "# Equivalent to the previous integer array indexing example\n", 1748 | "print np.array([a[0, 1], a[0, 1]])" 1749 | ], 1750 | "language": "python", 1751 | "metadata": {}, 1752 | "outputs": [ 1753 | { 1754 | "output_type": "stream", 1755 | "stream": "stdout", 1756 | "text": [ 1757 | "[2 2]\n", 1758 | "[2 2]\n" 1759 | ] 1760 | } 1761 | ], 1762 | "prompt_number": 221 1763 | }, 1764 | { 1765 | "cell_type": "markdown", 1766 | "metadata": {}, 1767 | "source": [ 1768 | "One useful trick with integer array indexing is selecting or mutating one element from each row of a matrix:" 1769 | ] 1770 | }, 1771 | { 1772 | "cell_type": "code", 1773 | "collapsed": false, 1774 | "input": [ 1775 | "# Create a new array from which we will select elements\n", 1776 | "a = np.array([[1,2,3], [4,5,6], [7,8,9], [10, 11, 12]])\n", 1777 | "print a" 1778 | ], 1779 | "language": "python", 1780 | "metadata": {}, 1781 | "outputs": [ 1782 | { 1783 | "output_type": "stream", 1784 | "stream": "stdout", 1785 | "text": [ 1786 | "[[ 1 2 3]\n", 1787 | " [ 4 5 6]\n", 1788 | " [ 7 8 9]\n", 1789 | " [10 11 12]]\n" 1790 | ] 1791 | } 1792 | ], 1793 | "prompt_number": 215 1794 | }, 1795 | { 1796 | "cell_type": "code", 1797 | "collapsed": false, 1798 | "input": [ 1799 | "# Create an array of indices\n", 1800 | "b = np.array([0, 2, 0, 1])\n", 1801 | "\n", 1802 | "# Select one element from each row of a using the indices in b\n", 1803 | "print a[np.arange(4), b] # Prints \"[ 1 6 7 11]\"" 1804 | ], 1805 | "language": "python", 1806 | "metadata": {}, 1807 | "outputs": [ 1808 | { 1809 | "output_type": "stream", 1810 | "stream": "stdout", 1811 | "text": [ 1812 | "[ 1 6 7 11]\n" 1813 | ] 1814 | } 1815 | ], 1816 | "prompt_number": 216 1817 | }, 1818 | { 1819 | "cell_type": "code", 1820 | "collapsed": false, 1821 | "input": [ 1822 | "# Mutate one element from each row of a using the indices in b\n", 1823 | "a[np.arange(4), b] += 10\n", 1824 | "print a" 1825 | ], 1826 | "language": "python", 1827 | "metadata": {}, 1828 | "outputs": [ 1829 | { 1830 | "output_type": "stream", 1831 | "stream": "stdout", 1832 | "text": [ 1833 | "[[11 2 3]\n", 1834 | " [ 4 5 16]\n", 1835 | " [17 8 9]\n", 1836 | " [10 21 12]]\n" 1837 | ] 1838 | } 1839 | ], 1840 | "prompt_number": 218 1841 | }, 1842 | { 1843 | "cell_type": "markdown", 1844 | "metadata": {}, 1845 | "source": [ 1846 | "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:" 1847 | ] 1848 | }, 1849 | { 1850 | "cell_type": "code", 1851 | "collapsed": false, 1852 | "input": [ 1853 | "import numpy as np\n", 1854 | "\n", 1855 | "a = np.array([[1,2], [3, 4], [5, 6]])\n", 1856 | "\n", 1857 | "bool_idx = (a > 2) # Find the elements of a that are bigger than 2;\n", 1858 | " # this returns a numpy array of Booleans of the same\n", 1859 | " # shape as a, where each slot of bool_idx tells\n", 1860 | " # whether that element of a is > 2.\n", 1861 | "\n", 1862 | "print bool_idx" 1863 | ], 1864 | "language": "python", 1865 | "metadata": {}, 1866 | "outputs": [ 1867 | { 1868 | "output_type": "stream", 1869 | "stream": "stdout", 1870 | "text": [ 1871 | "[[False False]\n", 1872 | " [ True True]\n", 1873 | " [ True True]]\n" 1874 | ] 1875 | } 1876 | ], 1877 | "prompt_number": 223 1878 | }, 1879 | { 1880 | "cell_type": "code", 1881 | "collapsed": false, 1882 | "input": [ 1883 | "# We use boolean array indexing to construct a rank 1 array\n", 1884 | "# consisting of the elements of a corresponding to the True values\n", 1885 | "# of bool_idx\n", 1886 | "print a[bool_idx]\n", 1887 | "\n", 1888 | "# We can do all of the above in a single concise statement:\n", 1889 | "print a[a > 2]" 1890 | ], 1891 | "language": "python", 1892 | "metadata": {}, 1893 | "outputs": [ 1894 | { 1895 | "output_type": "stream", 1896 | "stream": "stdout", 1897 | "text": [ 1898 | "[3 4 5 6]\n", 1899 | "[3 4 5 6]\n" 1900 | ] 1901 | } 1902 | ], 1903 | "prompt_number": 225 1904 | }, 1905 | { 1906 | "cell_type": "markdown", 1907 | "metadata": {}, 1908 | "source": [ 1909 | "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." 1910 | ] 1911 | }, 1912 | { 1913 | "cell_type": "heading", 1914 | "level": 3, 1915 | "metadata": {}, 1916 | "source": [ 1917 | "Datatypes" 1918 | ] 1919 | }, 1920 | { 1921 | "cell_type": "markdown", 1922 | "metadata": {}, 1923 | "source": [ 1924 | "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:" 1925 | ] 1926 | }, 1927 | { 1928 | "cell_type": "code", 1929 | "collapsed": false, 1930 | "input": [ 1931 | "x = np.array([1, 2]) # Let numpy choose the datatype\n", 1932 | "y = np.array([1.0, 2.0]) # Let numpy choose the datatype\n", 1933 | "z = np.array([1, 2], dtype=np.int64) # Force a particular datatype\n", 1934 | "\n", 1935 | "print x.dtype, y.dtype, z.dtype" 1936 | ], 1937 | "language": "python", 1938 | "metadata": {}, 1939 | "outputs": [ 1940 | { 1941 | "output_type": "stream", 1942 | "stream": "stdout", 1943 | "text": [ 1944 | "int64 float64 int64\n" 1945 | ] 1946 | } 1947 | ], 1948 | "prompt_number": 226 1949 | }, 1950 | { 1951 | "cell_type": "markdown", 1952 | "metadata": {}, 1953 | "source": [ 1954 | "You can read all about numpy datatypes in the [documentation](http://docs.scipy.org/doc/numpy/reference/arrays.dtypes.html)." 1955 | ] 1956 | }, 1957 | { 1958 | "cell_type": "heading", 1959 | "level": 3, 1960 | "metadata": {}, 1961 | "source": [ 1962 | "Array math" 1963 | ] 1964 | }, 1965 | { 1966 | "cell_type": "markdown", 1967 | "metadata": {}, 1968 | "source": [ 1969 | "Basic mathematical functions operate elementwise on arrays, and are available both as operator overloads and as functions in the numpy module:" 1970 | ] 1971 | }, 1972 | { 1973 | "cell_type": "code", 1974 | "collapsed": false, 1975 | "input": [ 1976 | "x = np.array([[1,2],[3,4]], dtype=np.float64)\n", 1977 | "y = np.array([[5,6],[7,8]], dtype=np.float64)\n", 1978 | "\n", 1979 | "# Elementwise sum; both produce the array\n", 1980 | "print x + y\n", 1981 | "print np.add(x, y)" 1982 | ], 1983 | "language": "python", 1984 | "metadata": {}, 1985 | "outputs": [ 1986 | { 1987 | "output_type": "stream", 1988 | "stream": "stdout", 1989 | "text": [ 1990 | "[[ 6. 8.]\n", 1991 | " [ 10. 12.]]\n", 1992 | "[[ 6. 8.]\n", 1993 | " [ 10. 12.]]\n" 1994 | ] 1995 | } 1996 | ], 1997 | "prompt_number": 227 1998 | }, 1999 | { 2000 | "cell_type": "code", 2001 | "collapsed": false, 2002 | "input": [ 2003 | "# Elementwise difference; both produce the array\n", 2004 | "print x - y\n", 2005 | "print np.subtract(x, y)" 2006 | ], 2007 | "language": "python", 2008 | "metadata": {}, 2009 | "outputs": [ 2010 | { 2011 | "output_type": "stream", 2012 | "stream": "stdout", 2013 | "text": [ 2014 | "[[-4. -4.]\n", 2015 | " [-4. -4.]]\n", 2016 | "[[-4. -4.]\n", 2017 | " [-4. -4.]]\n" 2018 | ] 2019 | } 2020 | ], 2021 | "prompt_number": 228 2022 | }, 2023 | { 2024 | "cell_type": "code", 2025 | "collapsed": false, 2026 | "input": [ 2027 | "# Elementwise product; both produce the array\n", 2028 | "print x * y\n", 2029 | "print np.multiply(x, y)" 2030 | ], 2031 | "language": "python", 2032 | "metadata": {}, 2033 | "outputs": [ 2034 | { 2035 | "output_type": "stream", 2036 | "stream": "stdout", 2037 | "text": [ 2038 | "[[ 5. 12.]\n", 2039 | " [ 21. 32.]]\n", 2040 | "[[ 5. 12.]\n", 2041 | " [ 21. 32.]]\n" 2042 | ] 2043 | } 2044 | ], 2045 | "prompt_number": 229 2046 | }, 2047 | { 2048 | "cell_type": "code", 2049 | "collapsed": false, 2050 | "input": [ 2051 | "# Elementwise division; both produce the array\n", 2052 | "# [[ 0.2 0.33333333]\n", 2053 | "# [ 0.42857143 0.5 ]]\n", 2054 | "print x / y\n", 2055 | "print np.divide(x, y)" 2056 | ], 2057 | "language": "python", 2058 | "metadata": {}, 2059 | "outputs": [ 2060 | { 2061 | "output_type": "stream", 2062 | "stream": "stdout", 2063 | "text": [ 2064 | "[[ 0.2 0.33333333]\n", 2065 | " [ 0.42857143 0.5 ]]\n", 2066 | "[[ 0.2 0.33333333]\n", 2067 | " [ 0.42857143 0.5 ]]\n" 2068 | ] 2069 | } 2070 | ], 2071 | "prompt_number": 230 2072 | }, 2073 | { 2074 | "cell_type": "code", 2075 | "collapsed": false, 2076 | "input": [ 2077 | "# Elementwise square root; produces the array\n", 2078 | "# [[ 1. 1.41421356]\n", 2079 | "# [ 1.73205081 2. ]]\n", 2080 | "print np.sqrt(x)" 2081 | ], 2082 | "language": "python", 2083 | "metadata": {}, 2084 | "outputs": [ 2085 | { 2086 | "output_type": "stream", 2087 | "stream": "stdout", 2088 | "text": [ 2089 | "[[ 1. 1.41421356]\n", 2090 | " [ 1.73205081 2. ]]\n" 2091 | ] 2092 | } 2093 | ], 2094 | "prompt_number": 231 2095 | }, 2096 | { 2097 | "cell_type": "markdown", 2098 | "metadata": {}, 2099 | "source": [ 2100 | "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 is available both as a function in the numpy module and as an instance method of array objects:" 2101 | ] 2102 | }, 2103 | { 2104 | "cell_type": "code", 2105 | "collapsed": false, 2106 | "input": [ 2107 | "x = np.array([[1,2],[3,4]])\n", 2108 | "y = np.array([[5,6],[7,8]])\n", 2109 | "\n", 2110 | "v = np.array([9,10])\n", 2111 | "w = np.array([11, 12])\n", 2112 | "\n", 2113 | "# Inner product of vectors; both produce 219\n", 2114 | "print v.dot(w)\n", 2115 | "print np.dot(v, w)" 2116 | ], 2117 | "language": "python", 2118 | "metadata": {}, 2119 | "outputs": [ 2120 | { 2121 | "output_type": "stream", 2122 | "stream": "stdout", 2123 | "text": [ 2124 | "219\n", 2125 | "219\n" 2126 | ] 2127 | } 2128 | ], 2129 | "prompt_number": 232 2130 | }, 2131 | { 2132 | "cell_type": "code", 2133 | "collapsed": false, 2134 | "input": [ 2135 | "# Matrix / vector product; both produce the rank 1 array [29 67]\n", 2136 | "print x.dot(v)\n", 2137 | "print np.dot(x, v)" 2138 | ], 2139 | "language": "python", 2140 | "metadata": {}, 2141 | "outputs": [ 2142 | { 2143 | "output_type": "stream", 2144 | "stream": "stdout", 2145 | "text": [ 2146 | "[29 67]\n", 2147 | "[29 67]\n" 2148 | ] 2149 | } 2150 | ], 2151 | "prompt_number": 233 2152 | }, 2153 | { 2154 | "cell_type": "code", 2155 | "collapsed": false, 2156 | "input": [ 2157 | "# Matrix / matrix product; both produce the rank 2 array\n", 2158 | "# [[19 22]\n", 2159 | "# [43 50]]\n", 2160 | "print x.dot(y)\n", 2161 | "print np.dot(x, y)" 2162 | ], 2163 | "language": "python", 2164 | "metadata": {}, 2165 | "outputs": [ 2166 | { 2167 | "output_type": "stream", 2168 | "stream": "stdout", 2169 | "text": [ 2170 | "[[19 22]\n", 2171 | " [43 50]]\n", 2172 | "[[19 22]\n", 2173 | " [43 50]]\n" 2174 | ] 2175 | } 2176 | ], 2177 | "prompt_number": 234 2178 | }, 2179 | { 2180 | "cell_type": "markdown", 2181 | "metadata": {}, 2182 | "source": [ 2183 | "Numpy provides many useful functions for performing computations on arrays; one of the most useful is `sum`:" 2184 | ] 2185 | }, 2186 | { 2187 | "cell_type": "code", 2188 | "collapsed": false, 2189 | "input": [ 2190 | "x = np.array([[1,2],[3,4]])\n", 2191 | "\n", 2192 | "print np.sum(x) # Compute sum of all elements; prints \"10\"\n", 2193 | "print np.sum(x, axis=0) # Compute sum of each column; prints \"[4 6]\"\n", 2194 | "print np.sum(x, axis=1) # Compute sum of each row; prints \"[3 7]\"" 2195 | ], 2196 | "language": "python", 2197 | "metadata": {}, 2198 | "outputs": [ 2199 | { 2200 | "output_type": "stream", 2201 | "stream": "stdout", 2202 | "text": [ 2203 | "10\n", 2204 | "[4 6]\n", 2205 | "[3 7]\n" 2206 | ] 2207 | } 2208 | ], 2209 | "prompt_number": 235 2210 | }, 2211 | { 2212 | "cell_type": "markdown", 2213 | "metadata": {}, 2214 | "source": [ 2215 | "You can find the full list of mathematical functions provided by numpy in the [documentation](http://docs.scipy.org/doc/numpy/reference/routines.math.html).\n", 2216 | "\n", 2217 | "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:" 2218 | ] 2219 | }, 2220 | { 2221 | "cell_type": "code", 2222 | "collapsed": false, 2223 | "input": [ 2224 | "print x\n", 2225 | "print x.T" 2226 | ], 2227 | "language": "python", 2228 | "metadata": {}, 2229 | "outputs": [ 2230 | { 2231 | "output_type": "stream", 2232 | "stream": "stdout", 2233 | "text": [ 2234 | "[[1 2]\n", 2235 | " [3 4]]\n", 2236 | "[[1 3]\n", 2237 | " [2 4]]\n" 2238 | ] 2239 | } 2240 | ], 2241 | "prompt_number": 236 2242 | }, 2243 | { 2244 | "cell_type": "code", 2245 | "collapsed": false, 2246 | "input": [ 2247 | "v = np.array([[1,2,3]])\n", 2248 | "print v \n", 2249 | "print v.T" 2250 | ], 2251 | "language": "python", 2252 | "metadata": {}, 2253 | "outputs": [ 2254 | { 2255 | "output_type": "stream", 2256 | "stream": "stdout", 2257 | "text": [ 2258 | "[[1 2 3]]\n", 2259 | "[[1]\n", 2260 | " [2]\n", 2261 | " [3]]\n" 2262 | ] 2263 | } 2264 | ], 2265 | "prompt_number": 237 2266 | }, 2267 | { 2268 | "cell_type": "heading", 2269 | "level": 3, 2270 | "metadata": {}, 2271 | "source": [ 2272 | "Broadcasting" 2273 | ] 2274 | }, 2275 | { 2276 | "cell_type": "markdown", 2277 | "metadata": {}, 2278 | "source": [ 2279 | "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", 2280 | "\n", 2281 | "For example, suppose that we want to add a constant vector to each row of a matrix. We could do it like this:" 2282 | ] 2283 | }, 2284 | { 2285 | "cell_type": "code", 2286 | "collapsed": false, 2287 | "input": [ 2288 | "# We will add the vector v to each row of the matrix x,\n", 2289 | "# storing the result in the matrix y\n", 2290 | "x = np.array([[1,2,3], [4,5,6], [7,8,9], [10, 11, 12]])\n", 2291 | "v = np.array([1, 0, 1])\n", 2292 | "y = np.empty_like(x) # Create an empty matrix with the same shape as x\n", 2293 | "\n", 2294 | "# Add the vector v to each row of the matrix x with an explicit loop\n", 2295 | "for i in range(4):\n", 2296 | " y[i, :] = x[i, :] + v\n", 2297 | "\n", 2298 | "print y" 2299 | ], 2300 | "language": "python", 2301 | "metadata": {}, 2302 | "outputs": [ 2303 | { 2304 | "output_type": "stream", 2305 | "stream": "stdout", 2306 | "text": [ 2307 | "[[ 2 2 4]\n", 2308 | " [ 5 5 7]\n", 2309 | " [ 8 8 10]\n", 2310 | " [11 11 13]]\n" 2311 | ] 2312 | } 2313 | ], 2314 | "prompt_number": 238 2315 | }, 2316 | { 2317 | "cell_type": "markdown", 2318 | "metadata": {}, 2319 | "source": [ 2320 | "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:" 2321 | ] 2322 | }, 2323 | { 2324 | "cell_type": "code", 2325 | "collapsed": false, 2326 | "input": [ 2327 | "vv = np.tile(v, (4, 1)) # Stack 4 copies of v on top of each other\n", 2328 | "print vv # Prints \"[[1 0 1]\n", 2329 | " # [1 0 1]\n", 2330 | " # [1 0 1]\n", 2331 | " # [1 0 1]]\"" 2332 | ], 2333 | "language": "python", 2334 | "metadata": {}, 2335 | "outputs": [ 2336 | { 2337 | "output_type": "stream", 2338 | "stream": "stdout", 2339 | "text": [ 2340 | "[[1 0 1]\n", 2341 | " [1 0 1]\n", 2342 | " [1 0 1]\n", 2343 | " [1 0 1]]\n" 2344 | ] 2345 | } 2346 | ], 2347 | "prompt_number": 240 2348 | }, 2349 | { 2350 | "cell_type": "code", 2351 | "collapsed": false, 2352 | "input": [ 2353 | "y = x + vv # Add x and vv elementwise\n", 2354 | "print y" 2355 | ], 2356 | "language": "python", 2357 | "metadata": {}, 2358 | "outputs": [ 2359 | { 2360 | "output_type": "stream", 2361 | "stream": "stdout", 2362 | "text": [ 2363 | "[[ 2 2 4]\n", 2364 | " [ 5 5 7]\n", 2365 | " [ 8 8 10]\n", 2366 | " [11 11 13]]\n" 2367 | ] 2368 | } 2369 | ], 2370 | "prompt_number": 241 2371 | }, 2372 | { 2373 | "cell_type": "markdown", 2374 | "metadata": {}, 2375 | "source": [ 2376 | "Numpy broadcasting allows us to perform this computation without actually creating multiple copies of v. Consider this version, using broadcasting:" 2377 | ] 2378 | }, 2379 | { 2380 | "cell_type": "code", 2381 | "collapsed": false, 2382 | "input": [ 2383 | "import numpy as np\n", 2384 | "\n", 2385 | "# We will add the vector v to each row of the matrix x,\n", 2386 | "# storing the result in the matrix y\n", 2387 | "x = np.array([[1,2,3], [4,5,6], [7,8,9], [10, 11, 12]])\n", 2388 | "v = np.array([1, 0, 1])\n", 2389 | "y = x + v # Add v to each row of x using broadcasting\n", 2390 | "print y" 2391 | ], 2392 | "language": "python", 2393 | "metadata": {}, 2394 | "outputs": [ 2395 | { 2396 | "output_type": "stream", 2397 | "stream": "stdout", 2398 | "text": [ 2399 | "[[ 2 2 4]\n", 2400 | " [ 5 5 7]\n", 2401 | " [ 8 8 10]\n", 2402 | " [11 11 13]]\n" 2403 | ] 2404 | } 2405 | ], 2406 | "prompt_number": 242 2407 | }, 2408 | { 2409 | "cell_type": "markdown", 2410 | "metadata": {}, 2411 | "source": [ 2412 | "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", 2413 | "\n", 2414 | "Broadcasting two arrays together follows these rules:\n", 2415 | "\n", 2416 | "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", 2417 | "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", 2418 | "3. The arrays can be broadcast together if they are compatible in all dimensions.\n", 2419 | "4. After broadcasting, each array behaves as if it had shape equal to the elementwise maximum of shapes of the two input arrays.\n", 2420 | "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", 2421 | "\n", 2422 | "If this explanation does not make sense, try reading the explanation from the [documentation](http://docs.scipy.org/doc/numpy/user/basics.broadcasting.html) or this [explanation](http://wiki.scipy.org/EricsBroadcastingDoc).\n", 2423 | "\n", 2424 | "Functions that support broadcasting are known as universal functions. You can find the list of all universal functions in the [documentation](http://docs.scipy.org/doc/numpy/reference/ufuncs.html#available-ufuncs).\n", 2425 | "\n", 2426 | "Here are some applications of broadcasting:" 2427 | ] 2428 | }, 2429 | { 2430 | "cell_type": "code", 2431 | "collapsed": false, 2432 | "input": [ 2433 | "# Compute outer product of vectors\n", 2434 | "v = np.array([1,2,3]) # v has shape (3,)\n", 2435 | "w = np.array([4,5]) # w has shape (2,)\n", 2436 | "# To compute an outer product, we first reshape v to be a column\n", 2437 | "# vector of shape (3, 1); we can then broadcast it against w to yield\n", 2438 | "# an output of shape (3, 2), which is the outer product of v and w:\n", 2439 | "\n", 2440 | "print np.reshape(v, (3, 1)) * w" 2441 | ], 2442 | "language": "python", 2443 | "metadata": {}, 2444 | "outputs": [ 2445 | { 2446 | "output_type": "stream", 2447 | "stream": "stdout", 2448 | "text": [ 2449 | "[[ 4 5]\n", 2450 | " [ 8 10]\n", 2451 | " [12 15]]\n" 2452 | ] 2453 | } 2454 | ], 2455 | "prompt_number": 243 2456 | }, 2457 | { 2458 | "cell_type": "code", 2459 | "collapsed": false, 2460 | "input": [ 2461 | "# Add a vector to each row of a matrix\n", 2462 | "x = np.array([[1,2,3], [4,5,6]])\n", 2463 | "# x has shape (2, 3) and v has shape (3,) so they broadcast to (2, 3),\n", 2464 | "# giving the following matrix:\n", 2465 | "\n", 2466 | "print x + v" 2467 | ], 2468 | "language": "python", 2469 | "metadata": {}, 2470 | "outputs": [ 2471 | { 2472 | "output_type": "stream", 2473 | "stream": "stdout", 2474 | "text": [ 2475 | "[[2 4 6]\n", 2476 | " [5 7 9]]\n" 2477 | ] 2478 | } 2479 | ], 2480 | "prompt_number": 244 2481 | }, 2482 | { 2483 | "cell_type": "code", 2484 | "collapsed": false, 2485 | "input": [ 2486 | "# Add a vector to each column of a matrix\n", 2487 | "# x has shape (2, 3) and w has shape (2,).\n", 2488 | "# If we transpose x then it has shape (3, 2) and can be broadcast\n", 2489 | "# against w to yield a result of shape (3, 2); transposing this result\n", 2490 | "# yields the final result of shape (2, 3) which is the matrix x with\n", 2491 | "# the vector w added to each column. Gives the following matrix:\n", 2492 | "\n", 2493 | "print (x.T + w).T" 2494 | ], 2495 | "language": "python", 2496 | "metadata": {}, 2497 | "outputs": [ 2498 | { 2499 | "output_type": "stream", 2500 | "stream": "stdout", 2501 | "text": [ 2502 | "[[ 5 6 7]\n", 2503 | " [ 9 10 11]]\n" 2504 | ] 2505 | } 2506 | ], 2507 | "prompt_number": 245 2508 | }, 2509 | { 2510 | "cell_type": "code", 2511 | "collapsed": false, 2512 | "input": [ 2513 | "# Another solution is to reshape w to be a row vector of shape (2, 1);\n", 2514 | "# we can then broadcast it directly against x to produce the same\n", 2515 | "# output.\n", 2516 | "print x + np.reshape(w, (2, 1))" 2517 | ], 2518 | "language": "python", 2519 | "metadata": {}, 2520 | "outputs": [ 2521 | { 2522 | "output_type": "stream", 2523 | "stream": "stdout", 2524 | "text": [ 2525 | "[[ 5 6 7]\n", 2526 | " [ 9 10 11]]\n" 2527 | ] 2528 | } 2529 | ], 2530 | "prompt_number": 246 2531 | }, 2532 | { 2533 | "cell_type": "code", 2534 | "collapsed": false, 2535 | "input": [ 2536 | "# Multiply a matrix by a constant:\n", 2537 | "# x has shape (2, 3). Numpy treats scalars as arrays of shape ();\n", 2538 | "# these can be broadcast together to shape (2, 3), producing the\n", 2539 | "# following array:\n", 2540 | "print x * 2" 2541 | ], 2542 | "language": "python", 2543 | "metadata": {}, 2544 | "outputs": [ 2545 | { 2546 | "output_type": "stream", 2547 | "stream": "stdout", 2548 | "text": [ 2549 | "[[ 2 4 6]\n", 2550 | " [ 8 10 12]]\n" 2551 | ] 2552 | } 2553 | ], 2554 | "prompt_number": 247 2555 | }, 2556 | { 2557 | "cell_type": "markdown", 2558 | "metadata": {}, 2559 | "source": [ 2560 | "Broadcasting typically makes your code more concise and faster, so you should strive to use it where possible." 2561 | ] 2562 | }, 2563 | { 2564 | "cell_type": "markdown", 2565 | "metadata": {}, 2566 | "source": [ 2567 | "This brief overview has touched on many of the important things that you need to know about numpy, but is far from complete. Check out the [numpy reference](http://docs.scipy.org/doc/numpy/reference/) to find out much more about numpy." 2568 | ] 2569 | }, 2570 | { 2571 | "cell_type": "heading", 2572 | "level": 2, 2573 | "metadata": {}, 2574 | "source": [ 2575 | "Matplotlib" 2576 | ] 2577 | }, 2578 | { 2579 | "cell_type": "markdown", 2580 | "metadata": {}, 2581 | "source": [ 2582 | "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." 2583 | ] 2584 | }, 2585 | { 2586 | "cell_type": "code", 2587 | "collapsed": false, 2588 | "input": [ 2589 | "import matplotlib.pyplot as plt" 2590 | ], 2591 | "language": "python", 2592 | "metadata": {}, 2593 | "outputs": [], 2594 | "prompt_number": 250 2595 | }, 2596 | { 2597 | "cell_type": "markdown", 2598 | "metadata": {}, 2599 | "source": [ 2600 | "By running this special iPython command, we will be displaying plots inline:" 2601 | ] 2602 | }, 2603 | { 2604 | "cell_type": "code", 2605 | "collapsed": false, 2606 | "input": [ 2607 | "%matplotlib inline" 2608 | ], 2609 | "language": "python", 2610 | "metadata": {}, 2611 | "outputs": [], 2612 | "prompt_number": 251 2613 | }, 2614 | { 2615 | "cell_type": "heading", 2616 | "level": 3, 2617 | "metadata": {}, 2618 | "source": [ 2619 | "Plotting" 2620 | ] 2621 | }, 2622 | { 2623 | "cell_type": "markdown", 2624 | "metadata": {}, 2625 | "source": [ 2626 | "The most important function in `matplotlib` is plot, which allows you to plot 2D data. Here is a simple example:" 2627 | ] 2628 | }, 2629 | { 2630 | "cell_type": "code", 2631 | "collapsed": false, 2632 | "input": [ 2633 | "# Compute the x and y coordinates for points on a sine curve\n", 2634 | "x = np.arange(0, 3 * np.pi, 0.1)\n", 2635 | "y = np.sin(x)\n", 2636 | "\n", 2637 | "# Plot the points using matplotlib\n", 2638 | "plt.plot(x, y)" 2639 | ], 2640 | "language": "python", 2641 | "metadata": {}, 2642 | "outputs": [ 2643 | { 2644 | "metadata": {}, 2645 | "output_type": "pyout", 2646 | "prompt_number": 252, 2647 | "text": [ 2648 | "[]" 2649 | ] 2650 | }, 2651 | { 2652 | "metadata": {}, 2653 | "output_type": "display_data", 2654 | "png": "iVBORw0KGgoAAAANSUhEUgAAAX0AAAEACAYAAABfxaZOAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3XeY1dW1//H30IsNROlKADFgQxAEQRkEqdKRIpYbDSFE\nIpbEkl+8kvt4DWrUmJBgjBoxAQEBKUpXRxCIFAFRehtAFEGEK9Ll/P5YM6E45cwp3/0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A5gLtCbaI/1zsUQnNqpdB1TAfvlNA9o6jch7tTg96a8F\nKuc8rpLzeYFcb7imxVt5q4X9Rv/IcRwuPQ/8GmvxjbIfAbuBf2Bt0X8HyjmNyJ29wLPANmAnsA8b\nGERZZazkQ85/KxfwXMB90tfirR86C6vfDgUOOI7FlZuBr7B6vp8O+nGhBLah4V9z/vsd0X03XAe4\nDxsUVcN+Vga4DMhnYsSRU10n/c+xCcxcNbHRflSVBCYC/8LKO1F1HdAV2AK8AdwIvO40Ind25Hws\nyfl8AgXvahtm1wALga+B48Ak7F6Jsl2c3DWhKjZY8jUt3jopA0tsz7sOxGdaEe2aPthOtvVyHg8j\n7xXtUXAV1tlWFvt5GQXc4zQi79XihxO5uV2PjxCAiVzQ4q1cLbH69QqsrLGck9tXRFkr1L1zFTbS\nX4mNbqPavQPWqZLbsjkKe3ccFW9gcxlHsbnQn2CT23MJUMumiIiIiIiIiIiIiIiIiIiIiIiIiIiI\niIiIiEgg/X8yZOyHNFXn6AAAAABJRU5ErkJggg==\n", 2655 | "text": [ 2656 | "" 2657 | ] 2658 | } 2659 | ], 2660 | "prompt_number": 252 2661 | }, 2662 | { 2663 | "cell_type": "markdown", 2664 | "metadata": {}, 2665 | "source": [ 2666 | "With just a little bit of extra work we can easily plot multiple lines at once, and add a title, legend, and axis labels:" 2667 | ] 2668 | }, 2669 | { 2670 | "cell_type": "code", 2671 | "collapsed": false, 2672 | "input": [ 2673 | "y_sin = np.sin(x)\n", 2674 | "y_cos = np.cos(x)\n", 2675 | "\n", 2676 | "# Plot the points using matplotlib\n", 2677 | "plt.plot(x, y_sin)\n", 2678 | "plt.plot(x, y_cos)\n", 2679 | "plt.xlabel('x axis label')\n", 2680 | "plt.ylabel('y axis label')\n", 2681 | "plt.title('Sine and Cosine')\n", 2682 | "plt.legend(['Sine', 'Cosine'])" 2683 | ], 2684 | "language": "python", 2685 | "metadata": {}, 2686 | "outputs": [ 2687 | { 2688 | "metadata": {}, 2689 | "output_type": "pyout", 2690 | "prompt_number": 254, 2691 | "text": [ 2692 | "" 2693 | ] 2694 | }, 2695 | { 2696 | "metadata": {}, 2697 | "output_type": "display_data", 2698 | "png": "iVBORw0KGgoAAAANSUhEUgAAAYwAAAEZCAYAAACEkhK6AAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzsnXdYVNf2v98BxIqKigV7A1HsvZvErmCNvSQ3icar15Sb\nxOQmuebml55oTL4pJrEbewUs2Hs3UWyIHVTsHQULs39/bFBUwAHOzJ457Pd5zuPMnHP2+TCeOWvv\ntddaGzQajUaj0Wg0Go1Go9FoNBqNRqPRaDQajUaj0Wg0Go1Go9FoNBqNRuPi9AdWqBZhA+uBVxx8\nzQ+APxx8TY1Go1FKM2ArcB24AmwG6ilVlHHWAf9IZ78fMA+4hPw7I4C3ADf7S9NobEPfjBpnJz+w\nBPgB8AZKAv8D7qoUZTAVgR1ANBAIFAReBOoCXgp1aTQajUtRD7iWzv6XgE0p3luBocCRpPN+euL4\nfwCHgKtAOFAmnbbnAeeQPf4NQNUU+6YAPyON2U1gO1Ahxf42wOGkc/+P9F1SfwJh6egACAYOIv+m\ndUCVFPtGAWeSdBwGnk/6/BNgetLrcsjvZhDSMF0C/pOiDQvwPnAMuAzMQRpojUajcRm8kA+wKUB7\nnn6IvcTTBiMUOTIpDVwE2iXt6wIcBfyRo+sPgS3pXPslIC+QA/ge2JNi35QkXfUAd+RDf1bSviLI\nh3f3pH1vAvdJ2yV1Dhicjg4/IA54Iam9d5P+jhxJf0sMUDzp2DI8Mlyjedpg/AbkBGoACUnnA7yB\ndPv5JrU7HpiZjiaNRqNxSqoAk4HTyAdvCFA0ad9LPG0wmqR4Pwd4L+n1ch5/aLsBt5GG5VkUTGo7\n2UU0Gfg9xf4OQGTS60HIh29KTpO2wbgHtE3n2h8Ds1O8tyBHFC2ASsAFpDHJ8cR5n/C0wfBNsX8H\n0CvpdSSPRiYAJZJ0abe15iH6ZtC4AoeBl5E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J3M0vmfveThQBnaciyWkmSJEmSJEmSJEmSJEmS\nJEnSsnKhg7JTtN9psvIbWSe/VKPAex2Ulzr2IEeDSMvJzg7KLiW3Z47OsrDMVlPX2WCoabaTp55X\nA+tIXMSWBcp9CVwu118r5x4lT8U+Qr4752lFZFdhj4MkjuMKeaJ4133q8wF5EvtnEt1R9zbwE0ke\nfqKc20QyoX4oR9PzkCSpq94BjgEnaL9T44byupb88FefXwVOkfj0D2vlb5TXt4BD5X0fSUWd72ta\nIYDV311Vzj9ZPs/QirvZSysT6zNavZkhsoseOCQlSV3xEOllfE/7YZ8jJJvrKvAPsKN27QzJL1tX\nO1c1GM+SLYPHSY7TQuoNxuvAj6U+14CXy/kZEhZX1fev8r6Kbq+O30s9RrHBUJf197oCUg9sJD+y\nq0gP4ua867vJjoXPALfID3y1tefDZEe/OWA92WOi7jxpNF4EPgaOA5+2qcfjpEeyDfiXbHS0pk3Z\nao6ijzRes22uS13jHIaa6CPgMBneWSjue4D0Km4Bm0nDUTlKGoBxsoPdfENkl7uT5Xh6kXoMkAbn\nOtnt7IXatT5gT3m/h+zlAEkVHauVe6pWXuoqexhqmhHgNvA5uWG6SHoUU7UyX5Ghol9IfP535fww\nWQ47Ru7oXwL2kajs6g7/OeAA8B8ZphpZpC7TZFjpVzK09G3t2hyZ35gmDdcr5fwY8H453w98A7zB\nEndMkyRJkiRJkiRJkiRJkiRJkiRJkiRJ0jJxF+in40AIXhGDAAAAAElFTkSuQmCC\n", 2699 | "text": [ 2700 | "" 2701 | ] 2702 | } 2703 | ], 2704 | "prompt_number": 254 2705 | }, 2706 | { 2707 | "cell_type": "heading", 2708 | "level": 3, 2709 | "metadata": {}, 2710 | "source": [ 2711 | "Subplots " 2712 | ] 2713 | }, 2714 | { 2715 | "cell_type": "markdown", 2716 | "metadata": {}, 2717 | "source": [ 2718 | "You can plot different things in the same figure using the subplot function. Here is an example:" 2719 | ] 2720 | }, 2721 | { 2722 | "cell_type": "code", 2723 | "collapsed": false, 2724 | "input": [ 2725 | "# Compute the x and y coordinates for points on sine and cosine curves\n", 2726 | "x = np.arange(0, 3 * np.pi, 0.1)\n", 2727 | "y_sin = np.sin(x)\n", 2728 | "y_cos = np.cos(x)\n", 2729 | "\n", 2730 | "# Set up a subplot grid that has height 2 and width 1,\n", 2731 | "# and set the first such subplot as active.\n", 2732 | "plt.subplot(2, 1, 1)\n", 2733 | "\n", 2734 | "# Make the first plot\n", 2735 | "plt.plot(x, y_sin)\n", 2736 | "plt.title('Sine')\n", 2737 | "\n", 2738 | "# Set the second subplot as active, and make the second plot.\n", 2739 | "plt.subplot(2, 1, 2)\n", 2740 | "plt.plot(x, y_cos)\n", 2741 | "plt.title('Cosine')\n", 2742 | "\n", 2743 | "# Show the figure.\n", 2744 | "plt.show()" 2745 | ], 2746 | "language": "python", 2747 | "metadata": {}, 2748 | "outputs": [ 2749 | { 2750 | "metadata": {}, 2751 | "output_type": "display_data", 2752 | "png": "iVBORw0KGgoAAAANSUhEUgAAAX0AAAEKCAYAAAD+XoUoAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3XmcjeX7wPHP2CqUpWwhSlJaJDv5Gkt+lPhWX2uWqEh9\nEVqohFKoRERC1sqSLTtZZuwhGkshIkvZl2wxzPP74zrnO2PMmOWc89zPeZ7r/Xqdl3PmPHPONcc5\n17mf+77u+wallFJKKaWUUkoppZRSSimllFJKKaWUUkoppZSy1bPAQtNBKKWUCq5HgdXAKeA4sBIo\nazQipZRSIXELkuwbAxHAjcBjwIMmg1JKKRUaZYGTydz3HLAiwe04oB2w0/c7nyc6vg3wC3ACWADc\nEcxAlVJKBe5m4BgwFqgD5Epw33Ncm/RnIWcHhYEjwP/57msA/AaUADIAbwOrQhe2Ukqp9LoXGAPs\nB2KB74G8JJ30Kye4PRl4w3d9PtLS98sAnEO+HJRypAymA1DKkO1AayRBPwDcDgwCrCSOPZTg+nkg\nu+96EeAzpNvnJDIgDFAwBPEqF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P+90XnzPfRO\noQAAAABJRU5ErkJggg==\n", 2753 | "text": [ 2754 | "" 2755 | ] 2756 | } 2757 | ], 2758 | "prompt_number": 255 2759 | }, 2760 | { 2761 | "cell_type": "markdown", 2762 | "metadata": {}, 2763 | "source": [ 2764 | "You can read much more about the `subplot` function in the [documentation](http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.subplot)." 2765 | ] 2766 | }, 2767 | { 2768 | "cell_type": "code", 2769 | "collapsed": false, 2770 | "input": [], 2771 | "language": "python", 2772 | "metadata": {}, 2773 | "outputs": [] 2774 | } 2775 | ], 2776 | "metadata": {} 2777 | } 2778 | ] 2779 | } 2780 | --------------------------------------------------------------------------------