Skip to content
Snippets Groups Projects
Preliminaries_Numpy_Pandas.ipynb 75.9 KiB
Newer Older
{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Functions, Conditionals, and Iteration in Python\n",
    "\n",
    "Let us create a Python function, and call it from a loop."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Hello World, x was < 10\n",
      "3\n"
     ]
    }
   ],
   "source": [
    "def HelloWorldXY(x, y):\n",
    "    if (x < 10):\n",
    "        print(\"Hello World, x was < 10\")\n",
    "    elif (x < 20):\n",
    "        print(\"Hello World, x was >= 10 but < 20\")\n",
    "    else:\n",
    "        print(\"Hello World, x was >= 20\")\n",
    "    return x + y\n",
    "\n",
    "print(HelloWorldXY(1,2))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Now let us call the function `HelloWorldXY()` from a loop:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "--- Now running with i: 8\n",
      "Hello World, x was < 10\n",
      "Result from HelloWorld: 16\n",
      "\n",
      "--- Now running with i: 13\n",
      "Hello World, x was >= 10 but < 20\n",
      "Result from HelloWorld: 26\n",
      "\n",
      "--- Now running with i: 18\n",
      "Hello World, x was >= 10 but < 20\n",
      "Result from HelloWorld: 36\n",
      "\n",
      "--- Now running with i: 23\n",
      "Hello World, x was >= 20\n",
      "Result from HelloWorld: 46\n"
     ]
    }
   ],
   "source": [
    "for i in range(8, 25, 5): # i=8, 13, 18, 23 (start, stop, step)\n",
    "    print(\"\\n--- Now running with i: {}\".format(i))\n",
    "    r = HelloWorldXY(i,i)\n",
    "    print(\"Result from HelloWorld: {}\".format(r))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "If you want a loop starting at 0 to 2 (exclusive) you could do any of the following:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Iterate over the items. `range(2)` is like a list [0,1].\n",
      "0\n",
      "1\n",
      "Iterate over an actual list.\n",
      "0\n",
     ]
    }
   ],
   "source": [
    "print(\"Iterate over the items. `range(2)` is like a list [0,1].\")\n",
    "for i in range(2):\n",
    "    print(i)\n",
    "\n",
    "print(\"Iterate over an actual list.\")\n",
    "for i in [0,1]:\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "While works\n",
      "0\n",
      "1\n",
      "Python supports standard key words like continue and break\n",
      "Entered while\n",
      "while broken\n"
     ]
    }
   ],
   "source": [
    "print(\"While works\")\n",
    "i = 0\n",
    "while i < 2:\n",
    "    print(i)\n",
    "    i += 1\n",
    "    \n",
    "print(\"Python supports standard key words like continue and break\")\n",
    "while True:\n",
    "    print(\"Entered while\")\n",
    "    break\n",
    "print(\"while broken\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## NumPy\n",
    "\n",
    "### Introducing NumPy\n",
    "\n",
    "Python is convenient, but it can also be slow. However, it does \n",
    "allow you to access libraries that execute faster code written in \n",
    "languages like C. NumPy is one such library: it provides fast alternatives \n",
    "to math operations in Python and is designed to work efficiently with \n",
    "groups of numbers - like matrices.\n",
    "\n",
    "NumPy is a large library and we are only going to scratch the surface \n",
    "of it here. If you plan on doing much math with Python, you should \n",
    "definitely spend some time exploring its documentation to learn more.\n",
    "\n",
    "### Importing Numpy\n",
    "\n",
    "When importing the NumPy library, the convention you will see \n",
    "used most often - including here - is to name it `np`, like so:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Now you can use the library by prefixing the names of functions and \n",
    "types with `np`, which you will see in the following examples.\n",
    "\n",
    "### Data Types and Shapes\n",
    "\n",
    "The most common way to work with numbers in NumPy is through `ndarray` \n",
    "objects. They are similar to Python lists, but can have any number of \n",
    "dimensions. Also, `ndarray` supports fast math operations, which \n",
    "is just what we want.\n",
    "\n",
    "Since it can store any number of dimensions, you can use `ndarrays` \n",
    "to represent any of the data types : scalars, vectors, \n",
    "matrices, or tensors. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Scalars\n",
    "\n",
    "Scalars in NumPy are a bit more involved than in Python. Instead of \n",
    "Python's basic types like `int`, `float`, etc., NumPy lets \n",
    "you specify signed and unsigned types, as well as different sizes.\n",
    "So instead of Python's `int`, you have access to types \n",
    "like `uint8`, `int8`, `uint16`, `int16`, and so on.\n",
    "\n",
    "These types are important because every object you make \n",
    "(vectors, matrices, tensors) eventually stores scalars. And when you \n",
    "create a NumPy array, you can specify the type - _but every item in the \n",
    "array must have the same type_. In this regard, NumPy arrays are more \n",
    "like C arrays than Python lists.\n",
    "\n",
    "If you want to create a NumPy array that holds a scalar, you do so \n",
    "by passing the value to NumPy's `array` function, as follows:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(5)"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Scalar\n",
    "s = np.array(5)\n",
241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748
    "s"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "You can display the number of axes of a NumPy `array` via the `ndim` attribute;\n",
    "a scalar array has $0$ axes (`ndim` == 0). The number of axes of an array is also\n",
    "called its _rank_. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s.ndim"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "You can see the shape of your arrays by checking their `shape` attribute. So if \n",
    "you executed this code:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "()"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s.shape"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "it would print out the result, an empty pair of parenthesis, `()`. This \n",
    "indicates that it has zero dimensions.\n",
    "\n",
    "Even though scalars are inside arrays, you still use them like a normal scalar. \n",
    "So you could type:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "numpy.int64"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x = s + 3\n",
    "type(x)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "and $x$ would now equal $8$. If you were to check the type of \n",
    "$x$, you would find it is probably `numPy.int64`, because \n",
    "it is working with NumPy types, not Python types.\n",
    "\n",
    "By the way, even scalar types support most of the array functions. \n",
    "So you can call `x.shape` and it would return `()` because \n",
    "it has zero dimensions, even though it is not an array. If you tried \n",
    "that with a normal Python scalar, you would get an error."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Vectors\n",
    "\n",
    "To create a vector, you would pass a Python list to the `array` function, like this:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([1, 2, 3])"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "v = np.array([1,2,3])\n",
    "v"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This vector has three entries and so is called a 3-dimensional vector. If you check a vector's `shape` attribute, it will return a single number representing the \n",
    "vector's one-dimensional length. In the above example, "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(3,)"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "v.shape"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Don’t confuse a 3D vector with a 3D array. A 3D vector has only one axis and has three dimensions along its axis, whereas a 3D array has three axes (and may have any number of dimensions along each axis). "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "v.ndim"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Dimensionality can denote either the number of entries along a specific\n",
    "axis (as in the case of our 3D vector) or the number of axes in an array (such as a\n",
    "3D array), which can be confusing at times.\n",
    "\n",
    "You can access an element within the vector using indices, like this:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "v[1]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "NumPy also supports advanced indexing techniques. For example, to access the items from the \n",
    "second element onward, you would say:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([2, 3])"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "v[1:]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "NumPy slicing is quite powerful, \n",
    "allowing you to access any combination of items in an `ndarray`. But it can also be a bit complicated, \n",
    "so you should read up on it in the documentation."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Matrices\n",
    "\n",
    "You create matrices using `NumPy`'s array function, just you did for vectors. However, instead \n",
    "of just passing in a list, you need to supply a list of lists, where each list represents \n",
    "a row. So to create a $3\\times 3$ matrix containing the numbers one through nine, you could \n",
    "do this:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1, 2, 3],\n",
       "       [4, 5, 6],\n",
       "       [7, 8, 9]])"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "m = np.array([[1,2,3], [4,5,6], [7,8,9]])\n",
    "m"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The entries from the first axis are called the _rows_, and the entries from \n",
    "the second axis are called the _columns_. A matrix thus has two axes or _rank_ 2:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "m.ndim"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Checking its shape attribute would return the tuple `(3, 3)` to indicate it has two dimensions, each length $3$:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(3, 3)"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "m.shape"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "You can access elements of matrices just like vectors, but using additional index values. So to find \n",
    "the number $6$ in the above matrix, you would access"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "6"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "m[1][2]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Tensors\n",
    "\n",
    "Tensors are just like vectors and matrices, but they can have more dimensions. For example, to \n",
    "create a $3\\times 3\\times 2\\times 1$ tensor, you could do the following:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[[[ 1],\n",
       "         [ 2]],\n",
       "\n",
       "        [[ 3],\n",
       "         [ 4]],\n",
       "\n",
       "        [[ 5],\n",
       "         [ 6]]],\n",
       "\n",
       "\n",
       "       [[[ 7],\n",
       "         [ 8]],\n",
       "\n",
       "        [[ 9],\n",
       "         [10]],\n",
       "\n",
       "        [[11],\n",
       "         [12]]],\n",
       "\n",
       "\n",
       "       [[[13],\n",
       "         [14]],\n",
       "\n",
       "        [[15],\n",
       "         [16]],\n",
       "\n",
       "        [[17],\n",
       "         [17]]]])"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "t = np.array([[[[1],[2]],[[3],[4]],[[5],[6]]],[[[7],[8]],\\\n",
    "    [[9],[10]],[[11],[12]]],[[[13],[14]],[[15],[16]],[[17],[17]]]])\n",
    "t"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "And `t.shape` returns `(3, 3, 2, 1)` and `t.ndim` indicates that we are dealing with a rank 4 tensor."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(3, 3, 2, 1)"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "t.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "t.ndim"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "You can access items just like with matrices, but with more indices. So "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "16"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "t[2][1][1][0]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Changing Shapes\n",
    "\n",
    "Sometimes you will need to change the shape of your data without actually changing \n",
    "its contents. For example, you may have a vector, which is one-dimensional, but need \n",
    "a matrix, which is two-dimensional. There are two ways you can do that.\n",
    "\n",
    "Let's say you have the following vector:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(4,)"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "v = np.array([1,2,3,4])\n",
    "v.shape"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Calling `v.shape` would return `(4,)`. But what if you want a $1\\times 4$ matrix? \n",
    "You can accomplish that with the `reshape` function, like so:\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1, 2, 3, 4]])"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x = v.reshape(1,4)\n",
    "x"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Calling `x.shape` would return `(1,4)`. If you wanted a $4\\times 1$ matrix, you \n",
    "could do this:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1],\n",
       "       [2],\n",
       "       [3],\n",
       "       [4]])"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x = v.reshape(4,1)\n",
    "x"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The `reshape` function works for more than just adding a dimension of size $1$. Check out its \n",
    "documentation for more examples.\n",
    "\n",
    "One more thing about reshaping NumPy arrays: if you see code from experienced NumPy users, you \n",
    "will often see them use a special slicing syntax instead of calling `reshape`. Using this \n",
    "syntax, the previous two examples would look like this:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1, 2, 3, 4]])"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x = v[None, :]\n",
    "x"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(4, 1)"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1],\n",
       "       [2],\n",
       "       [3],\n",
       "       [4]])"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x = v[:, None]\n",
    "x"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(4, 1)"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x.shape"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Those lines create a slice that looks at all of the items of `v` but asks NumPy to add a new dimension \n",
    "of size $1$ for the associated axis. It may look strange to you now, but it's a common technique so \n",
    "it's good to be aware of it. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Element-wise Operations\n",
    "\n",
    "#### The Python Way\n",
    "\n",
    "Suppose you had a list of numbers, and you wanted to add $5$ to every item in the list. \n",
    "Without NumPy, you might do something like this:"
   ]
  },
  {
   "cell_type": "code",
Mirko Birbaumer's avatar
Mirko Birbaumer committed
   "execution_count": 96,
   "metadata": {},
   "outputs": [
    {
Mirko Birbaumer's avatar
Mirko Birbaumer committed
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "853 ns ± 38.3 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)\n"
     ]
    }
   ],
   "source": [
Mirko Birbaumer's avatar
Mirko Birbaumer committed
    "%%timeit\n",
    "values = [1,2,3,4,5]\n",
    "for i in range(len(values)):\n",
    "    values[i] += 5\n",
    "    \n",
    "values"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "That makes sense, but it's a lot of code to write and it runs slowly because \n",
    "it's pure Python.\n",
    "\n",
    "__Note:__ Just in case you aren't used to using operators like `+=`, that just \n",
    "means _add these two items and then store the result in the left item._ It is a more \n",
    "succinct way of writing `values[i] = values[i] + 5`. The code you see in these examples \n",
    "makes use of such operators whenever possible."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### The NumPy Way\n",
    "\n",
    "In NumPy, we could do the following:\n"
   ]
  },
  {
   "cell_type": "code",
Mirko Birbaumer's avatar
Mirko Birbaumer committed
   "execution_count": 97,
   "metadata": {},
Mirko Birbaumer's avatar
Mirko Birbaumer committed
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3.24 µs ± 170 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)\n"
     ]
    }
   ],
   "source": [
Mirko Birbaumer's avatar
Mirko Birbaumer committed
    "%%timeit\n",
    "values = [1,2,3,4,5]\n",
Mirko Birbaumer's avatar
Mirko Birbaumer committed
    "values = np.array(values) + 5\n",
    "values"
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Creating that array may seem odd, but normally you'll be storing your data in `ndarrays` \n",
    "anyway. So if you already had an `ndarray` named `values`, you could have just done:"
   ]
  },
  {
   "cell_type": "code",
Mirko Birbaumer's avatar
Mirko Birbaumer committed
   "execution_count": 98,
   "metadata": {},
Mirko Birbaumer's avatar
Mirko Birbaumer committed
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "4.07 µs ± 262 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)\n"
     ]
    }
   ],
   "source": [
    "%%timeit\n",
    "values = [1,2,3,4,5]\n",
    "values = np.array(values)\n",
    "values += 5\n",
    "values"
   ]
Mirko Birbaumer's avatar
Mirko Birbaumer committed
   "cell_type": "markdown",
   "metadata": {},
Mirko Birbaumer's avatar
Mirko Birbaumer committed
   "source": [
    "We should point out, NumPy actually has functions for things like adding, multiplying, etc. \n",
    "But it also supports using the standard math operators. So the following two lines are equivalent:"
   ]
  },
  {
   "cell_type": "code",
Mirko Birbaumer's avatar
Mirko Birbaumer committed
   "execution_count": 59,
   "metadata": {},
Mirko Birbaumer's avatar
Mirko Birbaumer committed
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 5, 10, 15, 20])"
      ]
     },
     "execution_count": 59,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x = np.multiply(v, 5)\n",
    "x"
   ]
  },
  {
   "cell_type": "code",
Mirko Birbaumer's avatar
Mirko Birbaumer committed
   "execution_count": 60,
   "metadata": {},
Mirko Birbaumer's avatar
Mirko Birbaumer committed
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 5, 10, 15, 20])"
      ]
     },
     "execution_count": 60,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x = v * 5\n",
    "x"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We will usually use the operators instead of the functions because they are more convenient to \n",
    "type and easier to read, but it's really just personal preference.\n",
    "\n",
    "One more example of operating with scalars and `ndarrays`. Let's say you have a matrix `m` and you want \n",
    "to reuse it, but first you need to set all its values to zero. Easy, just multiply by zero and assign \n",
    "the result back to the matrix, like this:"
   ]
  {
   "cell_type": "code",
Mirko Birbaumer's avatar
Mirko Birbaumer committed
   "execution_count": 61,
   "metadata": {},
   "outputs": [
    {
Mirko Birbaumer's avatar
Mirko Birbaumer committed
     "data": {
      "text/plain": [
       "array([[0, 0, 0],\n",
       "       [0, 0, 0],\n",
       "       [0, 0, 0]])"
      ]
     },
     "execution_count": 61,
     "metadata": {},
     "output_type": "execute_result"
Mirko Birbaumer's avatar
Mirko Birbaumer committed
    "m *= 0\n",
    "m"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Element-wise Matrix Operations\n",
Mirko Birbaumer's avatar
Mirko Birbaumer committed
    "The same functions and operators that work with scalars and matrices also work with \n",
    "other dimensions. You just need to make sure that the items you perform the operation \n",
    "on have compatible shapes.\n",
Mirko Birbaumer's avatar
Mirko Birbaumer committed
    "Let's say you want to get the squared values of a matrix. That's simply `x = m * m` (or if you \n",
    "want to assign the value back to m, it's just `m *= m`\n",
Mirko Birbaumer's avatar
Mirko Birbaumer committed
    "This works because it's an element-wise multiplication between two identically-shaped matrices. \n",
    "(In this case, they are shaped the same because they are actually the same object.)\n",
Mirko Birbaumer's avatar
Mirko Birbaumer committed
    "Here's another example:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1, 3],\n",
       "       [5, 7]])"
      ]
     },
     "execution_count": 68,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = np.array([[1,3],[5,7]])\n",
Mirko Birbaumer's avatar
Mirko Birbaumer committed
    "a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[2, 4],\n",
       "       [6, 8]])"
      ]
     },
     "execution_count": 69,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "b = np.array([[2,4],[6,8]])\n",
Mirko Birbaumer's avatar
Mirko Birbaumer committed
    "b"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 3,  7],\n",
       "       [11, 15]])"
      ]
     },
     "execution_count": 70,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a + b"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
Mirko Birbaumer's avatar
Mirko Birbaumer committed
    "And if you try working with incompatible shapes, you would get an error:"
   ]
  },
  {
   "cell_type": "code",
Mirko Birbaumer's avatar
Mirko Birbaumer committed
   "execution_count": 71,
   "metadata": {},
   "outputs": [
    {
Mirko Birbaumer's avatar
Mirko Birbaumer committed
     "data": {
      "text/plain": [
       "array([[1, 3],\n",
       "       [5, 7]])"
      ]
     },
     "execution_count": 71,
     "metadata": {},
     "output_type": "execute_result"
Mirko Birbaumer's avatar
Mirko Birbaumer committed
    "a = np.array([[1,3],[5,7]])\n",
    "a"
Mirko Birbaumer's avatar
Mirko Birbaumer committed
   "cell_type": "code",
   "execution_count": 72,
   "metadata": {},
Mirko Birbaumer's avatar
Mirko Birbaumer committed
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[2, 3, 6],\n",
       "       [4, 5, 9],\n",
       "       [1, 8, 7]])"
      ]
     },
     "execution_count": 72,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
Mirko Birbaumer's avatar
Mirko Birbaumer committed
    "c = np.array([[2,3,6],[4,5,9],[1,8,7]])\n",
    "c"
   ]
  },
  {
   "cell_type": "code",
Mirko Birbaumer's avatar
Mirko Birbaumer committed
   "execution_count": 73,
   "metadata": {},
   "outputs": [
    {
Mirko Birbaumer's avatar
Mirko Birbaumer committed
     "data": {
      "text/plain": [
       "(2, 2)"
      ]
     },
     "execution_count": 73,
     "metadata": {},
     "output_type": "execute_result"
Mirko Birbaumer's avatar
Mirko Birbaumer committed
    "a.shape"
Mirko Birbaumer's avatar
Mirko Birbaumer committed
   "cell_type": "code",
   "execution_count": 74,
   "metadata": {},
Mirko Birbaumer's avatar
Mirko Birbaumer committed
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(3, 3)"
      ]
     },
     "execution_count": 74,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
Mirko Birbaumer's avatar
Mirko Birbaumer committed
    "c.shape"
   ]
  },
  {
   "cell_type": "code",
Mirko Birbaumer's avatar
Mirko Birbaumer committed
   "execution_count": 75,
   "metadata": {},
   "outputs": [
    {
Mirko Birbaumer's avatar
Mirko Birbaumer committed
     "ename": "ValueError",
     "evalue": "operands could not be broadcast together with shapes (2,2) (3,3) ",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mValueError\u001b[0m                                Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-75-e81e582b6fa9>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0ma\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0mc\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[0;31mValueError\u001b[0m: operands could not be broadcast together with shapes (2,2) (3,3) "
Mirko Birbaumer's avatar
Mirko Birbaumer committed
    "a + c"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 76,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1, 2, 3],\n",
       "       [4, 5, 6]])"
      ]
     },
     "execution_count": 76,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "m = np.array([[1,2,3],[4,5,6]])\n",
    "m"
Mirko Birbaumer's avatar
Mirko Birbaumer committed
1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949
  {
   "cell_type": "code",
   "execution_count": 77,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0.25, 0.5 , 0.75],\n",
       "       [1.  , 1.25, 1.5 ]])"
      ]
     },
     "execution_count": 77,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "n = m * 0.25\n",
    "n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 79,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0.25, 1.  , 2.25],\n",
       "       [4.  , 6.25, 9.  ]])"
      ]
     },
     "execution_count": 79,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "m * n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 80,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0.25, 1.  , 2.25],\n",
       "       [4.  , 6.25, 9.  ]])"
      ]
     },
     "execution_count": 80,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.multiply(m, n)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "To find the matrix product, you use NumPy's `matmul` function.\n",
    "\n",
    "If you have compatible shapes, then it's as simple as this:\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 81,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1, 2, 3, 4],\n",
       "       [5, 6, 7, 8]])"
      ]
     },
     "execution_count": 81,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = np.array([[1,2,3,4],[5,6,7,8]])\n",
    "a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 82,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(2, 4)"
      ]
     },
     "execution_count": 82,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 83,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 1,  2,  3],\n",
       "       [ 4,  5,  6],\n",
       "       [ 7,  8,  9],\n",
       "       [10, 11, 12]])"
      ]
     },
     "execution_count": 83,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "b = np.array([[1,2,3],[4,5,6],[7,8,9],[10,11,12]])\n",
    "b"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 84,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(4, 3)"
      ]
     },
     "execution_count": 84,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "b.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 85,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 70,  80,  90],\n",
       "       [158, 184, 210]])"
      ]
     },
     "execution_count": 85,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "c = np.matmul(a, b)\n",
    "c"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 86,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(2, 3)"
      ]
     },
     "execution_count": 86,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "c.shape"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "If your matrices have incompatible shapes, you'll get an error, like the following:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 87,
   "metadata": {},
   "outputs": [
    {
     "ename": "ValueError",
     "evalue": "matmul: Input operand 1 has a mismatch in its core dimension 0, with gufunc signature (n?,k),(k,m?)->(n?,m?) (size 2 is different from 3)",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mValueError\u001b[0m                                Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-87-af3b88aa2232>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mmatmul\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mb\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0ma\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[0;31mValueError\u001b[0m: matmul: Input operand 1 has a mismatch in its core dimension 0, with gufunc signature (n?,k),(k,m?)->(n?,m?) (size 2 is different from 3)"
     ]
    }
   ],
   "source": [
    "np.matmul(b, a)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### NumPy's `dot` function\n",
    "\n",
    "You may sometimes see NumPy's `dot` function in places where you would expect a `matmul`. \n",
    "It turns out that the results of dot and matmul are the same if the matrices are two dimensional.\n",
    "\n",
    "So these two results are equivalent:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 88,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1, 2],\n",
       "       [3, 4]])"
      ]
     },
     "execution_count": 88,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = np.array([[1,2],[3,4]])\n",
    "a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 89,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 7, 10],\n",
       "       [15, 22]])"
      ]
     },
     "execution_count": 89,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.dot(a,a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 90,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 7, 10],\n",
       "       [15, 22]])"
      ]
     },
     "execution_count": 90,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a.dot(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 91,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 7, 10],\n",
       "       [15, 22]])"
      ]
     },
     "execution_count": 91,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.matmul(a,a)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "While these functions return the same results for two dimensional data, you should be careful \n",
    "about which you choose when working with other data shapes. You can read more about the \n",
    "differences, and find links to other NumPy functions, in the `matmul` and `dot` documentation. \n",
    "\n",
    "\n",
    "\n",
    "### Transpose\n",
    "\n",
    "Getting the transpose of a matrix is really easy in NumPy. Simply access \n",
    "its `T` attribute. There is also a `transpose()` function which \n",
    "returns the same thing, but you will rarely see that used anywhere because \n",
    "typing `T` is so much easier. \n",
    "\n",
    "For example:\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 92,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 1,  2,  3,  4],\n",
       "       [ 5,  6,  7,  8],\n",
       "       [ 9, 10, 11, 12]])"
      ]
     },
     "execution_count": 92,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "m = np.array([[1,2,3,4], [5,6,7,8], [9,10,11,12]])\n",
    "m"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 93,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 1,  5,  9],\n",
       "       [ 2,  6, 10],\n",
       "       [ 3,  7, 11],\n",
       "       [ 4,  8, 12]])"
      ]
     },
     "execution_count": 93,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "m.T"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "NumPy does this without actually moving any data in memory -\n",
    "it simply changes the way it indexes the original matrix - \n",
    "so it's quite efficient.\n",
    "\n",
    "However, that also means you need to be careful with how you modify objects, \n",
    "because they are sharing the same data. For example, with the same matrix `m` \n",
    "from above, let us make a new variable `m_t` that stores `m`'s transpose. \n",
    "Then look what happens if we modify a value in `m_t`:\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 94,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[  1,   5,   9],\n",
       "       [  2,   6,  10],\n",
       "       [  3,   7,  11],\n",
       "       [  4, 200,  12]])"
      ]
     },
     "execution_count": 94,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "m_t = m.T\n",
    "m_t[3][1] = 200\n",
    "m_t"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 95,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[  1,   2,   3,   4],\n",
       "       [  5,   6,   7, 200],\n",
       "       [  9,  10,  11,  12]])"
      ]
     },
     "execution_count": 95,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "m"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Notice how it modified both the transpose and the original matrix, too. \n",
    "That's because they are sharing the same copy of data. So remember to \n",
    "consider the transpose just as a different view of your matrix, rather \n",
    "than a different matrix entirely."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Geometric Interpretation of Matrix Operation"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The following example will show what matrices and vectors are good for. \n",
    "\n",
    "We are going to start with a picture of a bug."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 102,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.image.AxesImage at 0x7f56299e9250>"
      ]
     },
     "execution_count": 102,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAQEAAAD8CAYAAAB3lxGOAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/d3fzzAAAACXBIWXMAAAsTAAALEwEAmpwYAABXtklEQVR4nO39d3xc133g/X/OLdN7QQcIgASrWERRsmRZLpLtSI57Wyduj9eOkrWzSZ44xUk2m+yzm02y2V3ncX5ZZ/3EXtuJE8ctttxt9WJ1ihR7AwECgz693np+f8yQomRKIiVQBIX7fr2AuXPmzsyZcr9zzrmnCCklHo9n9VIudQY8Hs+l5QUBj2eV84KAx7PKeUHA41nlvCDg8axyXhDweFa5ixIEhBA3CyGOCCGOCyE+dTGew+PxLA+x3P0EhBAqcBR4AzANPAr8kpTy4LI+kcfjWRYXoyRwDXBcSjkupTSBrwJvuwjP4/F4loF2ER6zH5g66/o08IrnukMmk5HDw8MXISsej+e0xx9/fElKmX1m+sUIAudFCHErcCvA0NAQjz322KXKisezKgghJs+VfjGqAzlg8KzrA520p5FSfk5KuUtKuSub/bng5PF4XiIXIwg8CowJIUaEED7gfcBtF+F5PB7PMlj26oCU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n6PXrBL3ShBu9X0KO065x+9RM/5z8AsYNGum32Udp3xDuAYcDuQ6uwrgL/t5G8fsOsi5OdVtOuXTwJ7On9vulR5ArYBT3Tysx/4j530UeAR4DjwdcDfSQ90rh/v3D56ET+71/LU2YFLlp/Oc+/t/B04/d29lN+jF/rn9Rj0eFa5S10d8Hg8l5gXBDyeVc4LAh7PKucFAY9nlfOCgMezynlBwONZ5bwg4PGscl4Q8HhWuf8/+/9ClZoTc64AAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "%matplotlib inline \n",
    "\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "import matplotlib.image as mpimg\n",
    "img = mpimg.imread('stinkbug4.JPG')\n",
    "plt.imshow(img)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "If you open the picture with an image viewer, you can enlarge or reduce the picture or rotate it. Now the important question: What's going on behind the scene if you do rotate the picture? Or in other words: What does the computer do to achieve the rotation? \n",
    "\n",
    "One simple solution is using a matrices and vectors."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 105,
   "metadata": {},
   "outputs": [
    {
     "ename": "ModuleNotFoundError",
     "evalue": "No module named 'skimage'",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mModuleNotFoundError\u001b[0m                       Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-105-16d8c7ff678e>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0;32mimport\u001b[0m \u001b[0mskimage\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m      2\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0mskimage\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtransform\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mrescale\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m      3\u001b[0m \u001b[0mimg\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mrescale\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mimg\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m.2\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m      4\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m      5\u001b[0m \u001b[0mimg\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdelete\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mimg\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0marange\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m20\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0maxis\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;31mModuleNotFoundError\u001b[0m: No module named 'skimage'"
     ]
    }
   ],
   "source": [
    "import skimage\n",
    "from skimage.transform import rescale\n",
    "img = rescale(img, .2)\n",
    "\n",
    "img = np.delete(img,np.arange(20), axis=0)\n",
    "img = np.delete(img,np.arange(80,100), axis=0)\n",
    "img = np.delete(img,np.arange(20), axis=1)\n",
    "img = np.delete(img,np.arange(80,100), axis=1)\n",
    "\n",
    "col =np.zeros(img.shape[0]*img.shape[1])\n",
    "\n",
    "k = 0\n",
    "for i in np.arange(img.shape[0]):\n",
    "    for j in np.arange(img.shape[1]):\n",
    "        col[k] = np.round(.99*img[i,j,:],0)\n",
    "        k = k+1\n",
    "        \n",
    "image = np.array([np.repeat(np.arange(img.shape[0]),img.shape[1]), np.tile(np.arange(img.shape[1]),img.shape[0])]).T\n",
    "image[:,0] = image[:,0] - 40\n",
    "image[:,1] = image[:,1] - 40\n",
    "\n",
    "image = image[col==0,:]\n",
    "\n",
    "\n",
    "plt.plot(image[:,0],image[:,1],\"o\",color=\"black\")\n",
    "plt.axis('square')\n",
    "plt.xlim(-40,40)\n",
    "plt.ylim(-40,40)\n",
    "plt.savefig(\"bug01.eps\",bbox_inches=\"tight\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## A real use case"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[-0.27  0.45  0.64  0.31]] (1, 4)\n",
      "[[ 0.02   0.001 -0.03   0.036]\n",
      " [ 0.04  -0.003  0.025  0.009]\n",
      " [ 0.012 -0.045  0.28  -0.067]] (3, 4)\n",
      "Matrix multiplication gives:\n",
      " [[-0.01299  0.00664  0.13494]] \n",
      "or, equivalently:\n",
      " [[-0.01299]\n",
      " [ 0.00664]\n",
      " [ 0.13494]]\n"
     ]
    }
   ],
   "source": [
    "inputs = np.array([[-0.27, 0.45, 0.64, 0.31]])\n",
    "print(inputs, inputs.shape)\n",
    "\n",
    "weights = np.array([[0.02, 0.001, -0.03, 0.036], \n",
    "                    [0.04, -0.003, 0.025, 0.009], \n",
    "                    [0.012, -0.045, 0.28, -0.067]])\n",
    "print(weights, weights.shape)\n",
    "\n",
    "print(\"Matrix multiplication gives:\\n\", np.matmul(inputs, weights.T), \"\\nor, equivalently:\\n\", np.matmul(weights, inputs.T))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Some more useful Numpy methods"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Showing some basic math on arrays\n",
      "Max: 4\n",
      "Average: 2.0\n",
      "Max index: 2\n",
      "\n",
      "Use numpy to create a [3,3] dimension array with random number\n",
      "[[0.92371879 0.58999086 0.76979433]\n",
      " [0.48733651 0.44698554 0.91494542]\n",
      " [0.59130531 0.69632003 0.32785335]]\n"
     ]
    }
   ],
   "source": [
    "print(\"\\nShowing some basic math on arrays\")\n",
    "\n",
    "b = np.array([0,1,4,3,2])\n",
    "print(\"Max: {}\".format(np.max(b)))\n",
    "print(\"Average: {}\".format(np.average(b)))\n",
    "print(\"Max index: {}\".format(np.argmax(b)))\n",
    "\n",
    "print(\"\\nUse numpy to create a [3,3] dimension array with random number\")\n",
    "c = np.random.rand(3, 3)\n",
    "print(c)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}