├── Conditions and Loops.ipynb ├── Functions.ipynb ├── Python Basic Data Structures and in-built functions.ipynb ├── Python OOPs Concepts.ipynb ├── Python_basics.ipynb ├── README.md └── python_tutorial.pdf /Conditions and Loops.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Control Flow\n", 8 | "\n", 9 | "A program’s control flow is the order in which the program’s code executes. The control flow of a Python program is regulated by conditional statements, loops, and function calls. This section covers the if statement and for and while loops; functions are covered in the next class.\n", 10 | "\n", 11 | "![](https://www.researchgate.net/profile/Kay_Smarsly/publication/322509045/figure/fig1/AS:583153716215809@1516046088625/Control-flow-of-elementary-control-structures.png)\n", 12 | "\n", 13 | "\n", 14 | "\n", 15 | "## Python Indentation\n", 16 | "In Python, the code blocks are defined by a set of common or consistent number of spaces. This is called Python Indentation.\n", 17 | "\n", 18 | "The block scope will end at the first un-indented line.\n", 19 | "\n", 20 | "The best practice is to use on Tab space." 21 | ] 22 | }, 23 | { 24 | "cell_type": "markdown", 25 | "metadata": {}, 26 | "source": [ 27 | "##### Conditions \n", 28 | ">* IF\n", 29 | ">* IF else\n", 30 | ">* if elif else\n", 31 | "#### Loops\n", 32 | ">* While\n", 33 | ">* For \n", 34 | "#### Break\n", 35 | "#### Continue\n", 36 | "##### Comparision Operators\n", 37 | "- x == y\n", 38 | "- x!= y\n", 39 | "- x < y\n", 40 | "- x <= y\n", 41 | "- x > y\n", 42 | "- x >= y\n" 43 | ] 44 | }, 45 | { 46 | "cell_type": "markdown", 47 | "metadata": {}, 48 | "source": [ 49 | "##### IF condition" 50 | ] 51 | }, 52 | { 53 | "cell_type": "code", 54 | "execution_count": 1, 55 | "metadata": {}, 56 | "outputs": [], 57 | "source": [ 58 | "x=10\n", 59 | "y=20" 60 | ] 61 | }, 62 | { 63 | "cell_type": "markdown", 64 | "metadata": {}, 65 | "source": [ 66 | "##### Condition is -- I need check whther x is greater than y \n" 67 | ] 68 | }, 69 | { 70 | "cell_type": "markdown", 71 | "metadata": {}, 72 | "source": [ 73 | "##### syntax\n", 74 | "\n", 75 | ">* if (condition):\n", 76 | " statement1\n", 77 | " statement2\n" 78 | ] 79 | }, 80 | { 81 | "cell_type": "code", 82 | "execution_count": 2, 83 | "metadata": {}, 84 | "outputs": [], 85 | "source": [ 86 | "if(x>y):\n", 87 | " print(\"x is greater than y\")\n", 88 | " print(\"Data science class\")" 89 | ] 90 | }, 91 | { 92 | "cell_type": "code", 93 | "execution_count": 3, 94 | "metadata": {}, 95 | "outputs": [ 96 | { 97 | "name": "stdout", 98 | "output_type": "stream", 99 | "text": [ 100 | "x is greater than y\n", 101 | "Data science class\n" 102 | ] 103 | } 104 | ], 105 | "source": [ 106 | "if(xy):\n", 118 | " print(\"x is greater than y\")\n", 119 | "\n", 120 | " print(\"Data science class\")\n" 121 | ] 122 | }, 123 | { 124 | "cell_type": "code", 125 | "execution_count": 5, 126 | "metadata": {}, 127 | "outputs": [], 128 | "source": [ 129 | "if(x>y):\n", 130 | " print(\"x is greater than y\")\n", 131 | " print(\"Data science class\") \n" 132 | ] 133 | }, 134 | { 135 | "cell_type": "markdown", 136 | "metadata": {}, 137 | "source": [ 138 | "##### if else:" 139 | ] 140 | }, 141 | { 142 | "cell_type": "markdown", 143 | "metadata": {}, 144 | "source": [ 145 | "\n", 146 | ">* if (condition):\n", 147 | " * statement1\n", 148 | " * statement2\n", 149 | ">* else:\n", 150 | " * Statement4" 151 | ] 152 | }, 153 | { 154 | "cell_type": "code", 155 | "execution_count": 6, 156 | "metadata": {}, 157 | "outputs": [ 158 | { 159 | "name": "stdout", 160 | "output_type": "stream", 161 | "text": [ 162 | "enetering into else block\n", 163 | "x is lessthan y\n" 164 | ] 165 | } 166 | ], 167 | "source": [ 168 | "x=10\n", 169 | "y=20\n", 170 | "if(x>y):\n", 171 | " print(\"x is greater than y\")\n", 172 | "else:\n", 173 | " print(\"enetering into else block\")\n", 174 | " print(\"x is lessthan y\")" 175 | ] 176 | }, 177 | { 178 | "cell_type": "code", 179 | "execution_count": 7, 180 | "metadata": {}, 181 | "outputs": [ 182 | { 183 | "name": "stdout", 184 | "output_type": "stream", 185 | "text": [ 186 | "x is greater than y\n" 187 | ] 188 | } 189 | ], 190 | "source": [ 191 | "x=100\n", 192 | "y=20\n", 193 | "if(x>y):\n", 194 | " print(\"x is greater than y\")\n", 195 | "else:\n", 196 | " print(\"enetering into else block\")\n", 197 | " print(\"x is lessthan y\")\n" 198 | ] 199 | }, 200 | { 201 | "cell_type": "code", 202 | "execution_count": 8, 203 | "metadata": {}, 204 | "outputs": [ 205 | { 206 | "name": "stdout", 207 | "output_type": "stream", 208 | "text": [ 209 | "x is greater than y\n", 210 | "outside if\n" 211 | ] 212 | } 213 | ], 214 | "source": [ 215 | "x=100\n", 216 | "y=20\n", 217 | "if(x>y):\n", 218 | " print(\"x is greater than y\")\n", 219 | "else:\n", 220 | " print(\"enetering into else block\")\n", 221 | " print(\"x is lessthan y\")\n", 222 | "print(\"outside if\")" 223 | ] 224 | }, 225 | { 226 | "cell_type": "code", 227 | "execution_count": 11, 228 | "metadata": {}, 229 | "outputs": [ 230 | { 231 | "name": "stdout", 232 | "output_type": "stream", 233 | "text": [ 234 | "x is greater than y\n" 235 | ] 236 | } 237 | ], 238 | "source": [ 239 | "x=100\n", 240 | "y=20\n", 241 | "if(x>y):\n", 242 | " print(\"x is greater than y\")\n", 243 | "else:\n", 244 | " print(\"enetering into else block\")\n", 245 | " print(\"x is lessthan y\")\n", 246 | " print(\"outside if\")" 247 | ] 248 | }, 249 | { 250 | "cell_type": "markdown", 251 | "metadata": {}, 252 | "source": [ 253 | "##### if elif else\n", 254 | "\n", 255 | ">* if (condition):\n", 256 | " * statement1\n", 257 | " * statement2\n", 258 | " \n", 259 | ">*elif (condition):\n", 260 | " * statement1\n", 261 | " * statement2\n", 262 | " \n", 263 | ">*elif (condition):\n", 264 | " * statement1\n", 265 | " * statement2\n", 266 | ">*elif (condition):\n", 267 | " * statement1\n", 268 | " * statement2\n", 269 | " \n", 270 | ">* else:\n", 271 | " * Statement\n", 272 | "\n" 273 | ] 274 | }, 275 | { 276 | "cell_type": "markdown", 277 | "metadata": {}, 278 | "source": [ 279 | "## Marks \n", 280 | "marks=?\n", 281 | ">=90 --- distinction\n", 282 | "\n", 283 | ">80-90 -- Grade A\n", 284 | "\n", 285 | ">70-80 Grade B\n", 286 | "\n", 287 | ">60-70 Grade c\n", 288 | "\n", 289 | "<60 - Fail" 290 | ] 291 | }, 292 | { 293 | "cell_type": "code", 294 | "execution_count": 13, 295 | "metadata": {}, 296 | "outputs": [], 297 | "source": [ 298 | "marks=50" 299 | ] 300 | }, 301 | { 302 | "cell_type": "code", 303 | "execution_count": 14, 304 | "metadata": {}, 305 | "outputs": [ 306 | { 307 | "name": "stdout", 308 | "output_type": "stream", 309 | "text": [ 310 | "Fail\n" 311 | ] 312 | } 313 | ], 314 | "source": [ 315 | "if marks>=90:\n", 316 | " print(\"Distinction\")\n", 317 | "elif marks>80:\n", 318 | " print(\"Grade A\")\n", 319 | "elif marks>70:\n", 320 | " print(\"Grade B\")\n", 321 | "elif marks>60:\n", 322 | " print(\"Grade C\")\n", 323 | "else:\n", 324 | " print(\"Fail\")\n", 325 | " \n", 326 | " " 327 | ] 328 | }, 329 | { 330 | "cell_type": "code", 331 | "execution_count": 15, 332 | "metadata": {}, 333 | "outputs": [], 334 | "source": [ 335 | "x=100\n", 336 | "y=20" 337 | ] 338 | }, 339 | { 340 | "cell_type": "code", 341 | "execution_count": 16, 342 | "metadata": {}, 343 | "outputs": [ 344 | { 345 | "name": "stdout", 346 | "output_type": "stream", 347 | "text": [ 348 | "second if\n", 349 | "first if\n", 350 | "outside if\n" 351 | ] 352 | } 353 | ], 354 | "source": [ 355 | "if(x>20):\n", 356 | " if(y>10):\n", 357 | " print(\"second if\")\n", 358 | " print(\"first if\")\n", 359 | "print(\"outside if\")" 360 | ] 361 | }, 362 | { 363 | "cell_type": "code", 364 | "execution_count": 17, 365 | "metadata": {}, 366 | "outputs": [ 367 | { 368 | "name": "stdout", 369 | "output_type": "stream", 370 | "text": [ 371 | "first if\n", 372 | "outside if\n" 373 | ] 374 | } 375 | ], 376 | "source": [ 377 | "if(x>20):\n", 378 | " if(y>100):\n", 379 | " print(\"second if\")\n", 380 | " print(\"first if\")\n", 381 | "print(\"outside if\")" 382 | ] 383 | }, 384 | { 385 | "cell_type": "markdown", 386 | "metadata": {}, 387 | "source": [ 388 | "##### Loops" 389 | ] 390 | }, 391 | { 392 | "cell_type": "markdown", 393 | "metadata": {}, 394 | "source": [ 395 | " >* While Loop\n", 396 | ">* for Loop" 397 | ] 398 | }, 399 | { 400 | "cell_type": "markdown", 401 | "metadata": {}, 402 | "source": [ 403 | "# The while Statement\n", 404 | "\n", 405 | "The while statement in Python supports repeated execution of a statement or block of statements that is controlled by a conditional expression. \n", 406 | "\n", 407 | " count = 0\n", 408 | " while x > 0:\n", 409 | " x = x / 2 \n", 410 | " count += 1\n", 411 | " \n", 412 | " \n", 413 | "First, expression, which is known as the loop condition, is evaluated. If the condition is false, the while statement ends. If the loop condition is satisfied, the statement or statements that comprise the loop body are executed. When the loop body finishes executing, the loop condition is evaluated again, to see if another iteration should be performed. This process continues until the loop condition is false, at which point the while statement ends.\n", 414 | "\n", 415 | "The loop body should contain code that eventually makes the loop condition false, or the loop will never end unless an exception is raised or the loop body executes a break statement. A loop that is in a function’s body also ends if a return statement executes in the loop body, as the whole function ends in this case." 416 | ] 417 | }, 418 | { 419 | "cell_type": "markdown", 420 | "metadata": {}, 421 | "source": [ 422 | "syntax:\n", 423 | " >* while(condition):\n", 424 | " * Statements\n", 425 | " " 426 | ] 427 | }, 428 | { 429 | "cell_type": "code", 430 | "execution_count": 18, 431 | "metadata": {}, 432 | "outputs": [], 433 | "source": [ 434 | "x=20\n", 435 | "y=10" 436 | ] 437 | }, 438 | { 439 | "cell_type": "code", 440 | "execution_count": 19, 441 | "metadata": { 442 | "scrolled": false 443 | }, 444 | "outputs": [ 445 | { 446 | "data": { 447 | "text/plain": [ 448 | "'while(x>y):\\n print(\"x is greater than y \")\\n'" 449 | ] 450 | }, 451 | "execution_count": 19, 452 | "metadata": {}, 453 | "output_type": "execute_result" 454 | } 455 | ], 456 | "source": [ 457 | "# Infinite Loop \n", 458 | "\"\"\"while(x>y):\n", 459 | " print(\"x is greater than y \")\n", 460 | "\"\"\"" 461 | ] 462 | }, 463 | { 464 | "cell_type": "code", 465 | "execution_count": 20, 466 | "metadata": {}, 467 | "outputs": [], 468 | "source": [ 469 | "x=20\n", 470 | "y=10" 471 | ] 472 | }, 473 | { 474 | "cell_type": "code", 475 | "execution_count": 21, 476 | "metadata": { 477 | "scrolled": false 478 | }, 479 | "outputs": [ 480 | { 481 | "name": "stdout", 482 | "output_type": "stream", 483 | "text": [ 484 | "x is greater than y \n", 485 | "18\n", 486 | "x is greater than y \n", 487 | "16\n", 488 | "x is greater than y \n", 489 | "14\n", 490 | "x is greater than y \n", 491 | "12\n", 492 | "x is greater than y \n", 493 | "10\n" 494 | ] 495 | } 496 | ], 497 | "source": [ 498 | "\n", 499 | "while(x>y):\n", 500 | " print(\"x is greater than y \")\n", 501 | " x=x-2\n", 502 | " print(x)" 503 | ] 504 | }, 505 | { 506 | "cell_type": "markdown", 507 | "metadata": {}, 508 | "source": [ 509 | "##### break " 510 | ] 511 | }, 512 | { 513 | "cell_type": "code", 514 | "execution_count": 22, 515 | "metadata": {}, 516 | "outputs": [ 517 | { 518 | "name": "stdout", 519 | "output_type": "stream", 520 | "text": [ 521 | "x is greater than y \n" 522 | ] 523 | } 524 | ], 525 | "source": [ 526 | "x=20\n", 527 | "y=10\n", 528 | "while(x>y):\n", 529 | " print(\"x is greater than y \")\n", 530 | " break\n" 531 | ] 532 | }, 533 | { 534 | "cell_type": "code", 535 | "execution_count": 23, 536 | "metadata": {}, 537 | "outputs": [ 538 | { 539 | "name": "stdout", 540 | "output_type": "stream", 541 | "text": [ 542 | "x is greater than y \n", 543 | "before break\n" 544 | ] 545 | } 546 | ], 547 | "source": [ 548 | "x=20\n", 549 | "y=10\n", 550 | "while(x>y):\n", 551 | " print(\"x is greater than y \")\n", 552 | " print(\"before break\")\n", 553 | " break\n", 554 | " print(\"after break\")\n" 555 | ] 556 | }, 557 | { 558 | "cell_type": "markdown", 559 | "metadata": {}, 560 | "source": [ 561 | "##### continue " 562 | ] 563 | }, 564 | { 565 | "cell_type": "code", 566 | "execution_count": 24, 567 | "metadata": {}, 568 | "outputs": [ 569 | { 570 | "name": "stdout", 571 | "output_type": "stream", 572 | "text": [ 573 | "x is greater than y \n", 574 | "x is greater than y \n", 575 | "x is greater than y \n", 576 | "x is greater than y \n", 577 | "x is greater than y \n" 578 | ] 579 | } 580 | ], 581 | "source": [ 582 | "x=20\n", 583 | "y=10\n", 584 | "while(x>y):\n", 585 | " print(\"x is greater than y \")\n", 586 | " x=x-2\n", 587 | " continue\n", 588 | " print(x)" 589 | ] 590 | }, 591 | { 592 | "cell_type": "markdown", 593 | "metadata": {}, 594 | "source": [ 595 | "### Break:\n", 596 | "\n", 597 | "* Terminates the execution of current loop\n", 598 | "\n", 599 | "### Continue:\n", 600 | "\n", 601 | "* Returns the control to the beginning of the loop." 602 | ] 603 | }, 604 | { 605 | "cell_type": "markdown", 606 | "metadata": {}, 607 | "source": [ 608 | "#### For Loop\n", 609 | "\n", 610 | "The for statement in Python supports repeated execution of a statement or block of statements that is controlled by an iterable expression.\n", 611 | "\n", 612 | " for target in iterable:\n", 613 | " statement(s)\n", 614 | " \n", 615 | "Note that the in keyword is part of the syntax of the for statement and is functionally unrelated to the in operator used for membership testing. \n", 616 | "\n", 617 | "iterable may be any Python expression suitable as an argument to built-in function iter, which returns an iterator object (explained in detail in the next section). target is normally an identifier that names the control variable of the loop; the for statement successively rebinds this variable to each item of the iterator, in order. The statement or statements that comprise the loop body execute once for each item in iterable (unless the loop ends because an exception is raised or a break or return statement is executed)." 618 | ] 619 | }, 620 | { 621 | "cell_type": "markdown", 622 | "metadata": {}, 623 | "source": [ 624 | "##### syntax\n", 625 | ">* for i in variable:\n", 626 | " * stmnts" 627 | ] 628 | }, 629 | { 630 | "cell_type": "code", 631 | "execution_count": 25, 632 | "metadata": {}, 633 | "outputs": [], 634 | "source": [ 635 | "l=[1,2,3,4,5,6]" 636 | ] 637 | }, 638 | { 639 | "cell_type": "code", 640 | "execution_count": 26, 641 | "metadata": {}, 642 | "outputs": [ 643 | { 644 | "data": { 645 | "text/plain": [ 646 | "list" 647 | ] 648 | }, 649 | "execution_count": 26, 650 | "metadata": {}, 651 | "output_type": "execute_result" 652 | } 653 | ], 654 | "source": [ 655 | "type(l)" 656 | ] 657 | }, 658 | { 659 | "cell_type": "code", 660 | "execution_count": 27, 661 | "metadata": { 662 | "scrolled": true 663 | }, 664 | "outputs": [ 665 | { 666 | "name": "stdout", 667 | "output_type": "stream", 668 | "text": [ 669 | "1\n", 670 | "2\n", 671 | "3\n", 672 | "4\n" 673 | ] 674 | } 675 | ], 676 | "source": [ 677 | "print(l[0])\n", 678 | "print(l[1])\n", 679 | "print(l[2])\n", 680 | "print(l[3])" 681 | ] 682 | }, 683 | { 684 | "cell_type": "code", 685 | "execution_count": 28, 686 | "metadata": {}, 687 | "outputs": [ 688 | { 689 | "name": "stdout", 690 | "output_type": "stream", 691 | "text": [ 692 | "[1, 2, 3, 4, 5, 6]\n" 693 | ] 694 | } 695 | ], 696 | "source": [ 697 | "print(l)" 698 | ] 699 | }, 700 | { 701 | "cell_type": "code", 702 | "execution_count": 29, 703 | "metadata": { 704 | "scrolled": true 705 | }, 706 | "outputs": [ 707 | { 708 | "name": "stdout", 709 | "output_type": "stream", 710 | "text": [ 711 | "1\n", 712 | "2\n", 713 | "3\n", 714 | "4\n", 715 | "5\n", 716 | "6\n" 717 | ] 718 | } 719 | ], 720 | "source": [ 721 | "for i in l:\n", 722 | " print(i)" 723 | ] 724 | }, 725 | { 726 | "cell_type": "code", 727 | "execution_count": 30, 728 | "metadata": {}, 729 | "outputs": [ 730 | { 731 | "data": { 732 | "text/plain": [ 733 | "6" 734 | ] 735 | }, 736 | "execution_count": 30, 737 | "metadata": {}, 738 | "output_type": "execute_result" 739 | } 740 | ], 741 | "source": [ 742 | "len(l)" 743 | ] 744 | }, 745 | { 746 | "cell_type": "code", 747 | "execution_count": 31, 748 | "metadata": {}, 749 | "outputs": [ 750 | { 751 | "name": "stdout", 752 | "output_type": "stream", 753 | "text": [ 754 | "1\n", 755 | "2\n", 756 | "3\n", 757 | "4\n", 758 | "5\n", 759 | "6\n" 760 | ] 761 | } 762 | ], 763 | "source": [ 764 | "for i in range(0,len(l)):\n", 765 | " print(l[i])" 766 | ] 767 | }, 768 | { 769 | "cell_type": "markdown", 770 | "metadata": {}, 771 | "source": [ 772 | "## Difference between break and continue" 773 | ] 774 | }, 775 | { 776 | "cell_type": "code", 777 | "execution_count": 32, 778 | "metadata": { 779 | "scrolled": true 780 | }, 781 | "outputs": [ 782 | { 783 | "name": "stdout", 784 | "output_type": "stream", 785 | "text": [ 786 | "value of i is 1\n", 787 | "print of for loop\n", 788 | "secod print of for loop\n" 789 | ] 790 | } 791 | ], 792 | "source": [ 793 | "for i in range(1,10):\n", 794 | " print(\"value of i is\",i)\n", 795 | " print(\"print of for loop\")\n", 796 | " #continue\n", 797 | " if (i>3):\n", 798 | " print(\"print of if block\")\n", 799 | " print(\"secod print of for loop\")\n", 800 | " break" 801 | ] 802 | }, 803 | { 804 | "cell_type": "code", 805 | "execution_count": 33, 806 | "metadata": {}, 807 | "outputs": [ 808 | { 809 | "name": "stdout", 810 | "output_type": "stream", 811 | "text": [ 812 | "value of i is 1\n", 813 | "print of for loop\n", 814 | "value of i is 2\n", 815 | "print of for loop\n", 816 | "value of i is 3\n", 817 | "print of for loop\n", 818 | "value of i is 4\n", 819 | "print of for loop\n", 820 | "value of i is 5\n", 821 | "print of for loop\n", 822 | "value of i is 6\n", 823 | "print of for loop\n", 824 | "value of i is 7\n", 825 | "print of for loop\n", 826 | "value of i is 8\n", 827 | "print of for loop\n", 828 | "value of i is 9\n", 829 | "print of for loop\n" 830 | ] 831 | } 832 | ], 833 | "source": [ 834 | "for i in range(1,10):\n", 835 | " print(\"value of i is\",i)\n", 836 | " print(\"print of for loop\")\n", 837 | " continue\n", 838 | " if (i>3):\n", 839 | " print(\"print of if block\")\n", 840 | " print(\"secod print of for loop\")\n", 841 | " break" 842 | ] 843 | }, 844 | { 845 | "cell_type": "markdown", 846 | "metadata": {}, 847 | "source": [ 848 | "##### range() function\n", 849 | "\n", 850 | "Looping over a sequence of integers is a common task, so Python provides built-in functions range and xrange to generate and return integer sequences. The simplest, most idiomatic way to loop n times in Python is:\n", 851 | "\n", 852 | "\n", 853 | " for i in range(n):\n", 854 | " statement(s)\n", 855 | " \n", 856 | "range( x ) returns a list whose items are consecutive integers from 0 (included) up to x (excluded). range( x,y ) returns a list whose items are consecutive integers from x (included) up to y (excluded). The result is the empty list if x is greater than or equal to y. range( x,y,step ) returns a list of integers from x (included) up to y (excluded), such that the difference between each two adjacent items in the list is step. " 857 | ] 858 | }, 859 | { 860 | "cell_type": "code", 861 | "execution_count": 34, 862 | "metadata": {}, 863 | "outputs": [ 864 | { 865 | "data": { 866 | "text/plain": [ 867 | "[10, 12, 14, 16, 18, 20, 22, 24, 26, 28]" 868 | ] 869 | }, 870 | "execution_count": 34, 871 | "metadata": {}, 872 | "output_type": "execute_result" 873 | } 874 | ], 875 | "source": [ 876 | "list(range(10, 30, 2))" 877 | ] 878 | }, 879 | { 880 | "cell_type": "code", 881 | "execution_count": 35, 882 | "metadata": {}, 883 | "outputs": [ 884 | { 885 | "data": { 886 | "text/plain": [ 887 | "[30,\n", 888 | " 29,\n", 889 | " 28,\n", 890 | " 27,\n", 891 | " 26,\n", 892 | " 25,\n", 893 | " 24,\n", 894 | " 23,\n", 895 | " 22,\n", 896 | " 21,\n", 897 | " 20,\n", 898 | " 19,\n", 899 | " 18,\n", 900 | " 17,\n", 901 | " 16,\n", 902 | " 15,\n", 903 | " 14,\n", 904 | " 13,\n", 905 | " 12,\n", 906 | " 11]" 907 | ] 908 | }, 909 | "execution_count": 35, 910 | "metadata": {}, 911 | "output_type": "execute_result" 912 | } 913 | ], 914 | "source": [ 915 | "list(range(30, 10, -1))" 916 | ] 917 | }, 918 | { 919 | "cell_type": "code", 920 | "execution_count": 36, 921 | "metadata": { 922 | "scrolled": true 923 | }, 924 | "outputs": [ 925 | { 926 | "name": "stdout", 927 | "output_type": "stream", 928 | "text": [ 929 | "0\n", 930 | "1\n", 931 | "2\n", 932 | "3\n", 933 | "4\n", 934 | "5\n", 935 | "6\n", 936 | "7\n", 937 | "8\n", 938 | "9\n" 939 | ] 940 | } 941 | ], 942 | "source": [ 943 | "for i in range(10):\n", 944 | " print (i)" 945 | ] 946 | }, 947 | { 948 | "cell_type": "markdown", 949 | "metadata": {}, 950 | "source": [ 951 | "#### List Comprehensions\n", 952 | "\n", 953 | "A common use of a for loop is to inspect each item in a sequence and build a new list by appending the results of an expression computed on some or all of the items inspected. The expression form, called a list comprehension, lets you code this common idiom concisely and directly. Since a list comprehension is an expression (rather than a block of statements), you can use it directly wherever you need an expression (e.g., as an actual argument in a function call, in a return statement, or as a subexpression for some other expression)." 954 | ] 955 | }, 956 | { 957 | "cell_type": "code", 958 | "execution_count": 37, 959 | "metadata": {}, 960 | "outputs": [], 961 | "source": [ 962 | "mylst = [10,20,30]" 963 | ] 964 | }, 965 | { 966 | "cell_type": "code", 967 | "execution_count": 38, 968 | "metadata": {}, 969 | "outputs": [], 970 | "source": [ 971 | "l1=[]\n", 972 | "for l in mylst:\n", 973 | " l1.append(l+1)" 974 | ] 975 | }, 976 | { 977 | "cell_type": "code", 978 | "execution_count": 39, 979 | "metadata": {}, 980 | "outputs": [ 981 | { 982 | "name": "stdout", 983 | "output_type": "stream", 984 | "text": [ 985 | "[11, 21, 31]\n" 986 | ] 987 | } 988 | ], 989 | "source": [ 990 | "print(l1)" 991 | ] 992 | }, 993 | { 994 | "cell_type": "code", 995 | "execution_count": 40, 996 | "metadata": {}, 997 | "outputs": [ 998 | { 999 | "data": { 1000 | "text/plain": [ 1001 | "[11, 21, 31]" 1002 | ] 1003 | }, 1004 | "execution_count": 40, 1005 | "metadata": {}, 1006 | "output_type": "execute_result" 1007 | } 1008 | ], 1009 | "source": [ 1010 | "\n", 1011 | "[x+1 for x in mylst]" 1012 | ] 1013 | }, 1014 | { 1015 | "cell_type": "markdown", 1016 | "metadata": {}, 1017 | "source": [ 1018 | "##### Comparision Operators\n", 1019 | "- x == y\n", 1020 | "- x!= y\n", 1021 | "- x < y\n", 1022 | "- x <= y\n", 1023 | "- x > y\n", 1024 | "- x >= y\n" 1025 | ] 1026 | }, 1027 | { 1028 | "cell_type": "code", 1029 | "execution_count": 41, 1030 | "metadata": {}, 1031 | "outputs": [ 1032 | { 1033 | "name": "stdout", 1034 | "output_type": "stream", 1035 | "text": [ 1036 | "Equals to False\n", 1037 | "Not equals True\n", 1038 | "Less than True\n", 1039 | "Less than equal to True\n", 1040 | "Greater than False\n", 1041 | "Greater than equal to False\n" 1042 | ] 1043 | } 1044 | ], 1045 | "source": [ 1046 | "x=10\n", 1047 | "y=20\n", 1048 | "print(\"Equals to\",x==y)\n", 1049 | "print(\"Not equals\",x!=y)\n", 1050 | "print(\"Less than\",xy)\n", 1053 | "print(\"Greater than equal to\",x>=y)" 1054 | ] 1055 | }, 1056 | { 1057 | "cell_type": "markdown", 1058 | "metadata": {}, 1059 | "source": [ 1060 | "##### Boolean Operations\n", 1061 | ">* and\n", 1062 | ">* or\n", 1063 | ">* not" 1064 | ] 1065 | }, 1066 | { 1067 | "cell_type": "code", 1068 | "execution_count": 42, 1069 | "metadata": {}, 1070 | "outputs": [ 1071 | { 1072 | "name": "stdout", 1073 | "output_type": "stream", 1074 | "text": [ 1075 | "welcome to the job\n" 1076 | ] 1077 | } 1078 | ], 1079 | "source": [ 1080 | "age=21\n", 1081 | "marks=80\n", 1082 | "# Both Conditions should be true \n", 1083 | "if age >= 18 and marks > 50:\n", 1084 | " print (\"welcome to the job\")\n", 1085 | " \n", 1086 | "if age >= 18 and marks > 150:\n", 1087 | " print (\"welcome to the job1\")" 1088 | ] 1089 | }, 1090 | { 1091 | "cell_type": "code", 1092 | "execution_count": 43, 1093 | "metadata": {}, 1094 | "outputs": [ 1095 | { 1096 | "name": "stdout", 1097 | "output_type": "stream", 1098 | "text": [ 1099 | "welcome to the job\n", 1100 | "welcome to the job1\n" 1101 | ] 1102 | } 1103 | ], 1104 | "source": [ 1105 | "# Any one of the condition is true \n", 1106 | "if age >= 18 or marks > 50:\n", 1107 | " print (\"welcome to the job\")\n", 1108 | " \n", 1109 | "if age >= 18 or marks > 150:\n", 1110 | " print (\"welcome to the job1\")" 1111 | ] 1112 | }, 1113 | { 1114 | "cell_type": "code", 1115 | "execution_count": 44, 1116 | "metadata": {}, 1117 | "outputs": [ 1118 | { 1119 | "data": { 1120 | "text/plain": [ 1121 | "False" 1122 | ] 1123 | }, 1124 | "execution_count": 44, 1125 | "metadata": {}, 1126 | "output_type": "execute_result" 1127 | } 1128 | ], 1129 | "source": [ 1130 | "not age > 18" 1131 | ] 1132 | }, 1133 | { 1134 | "cell_type": "markdown", 1135 | "metadata": {}, 1136 | "source": [ 1137 | "##### Formatting" 1138 | ] 1139 | }, 1140 | { 1141 | "cell_type": "code", 1142 | "execution_count": 45, 1143 | "metadata": {}, 1144 | "outputs": [ 1145 | { 1146 | "name": "stdout", 1147 | "output_type": "stream", 1148 | "text": [ 1149 | "My name is Suresh, and I am 26\n" 1150 | ] 1151 | } 1152 | ], 1153 | "source": [ 1154 | "age = 26\n", 1155 | "txt = \"My name is Suresh, and I am \"+str(age)\n", 1156 | "print (txt)" 1157 | ] 1158 | }, 1159 | { 1160 | "cell_type": "code", 1161 | "execution_count": 46, 1162 | "metadata": {}, 1163 | "outputs": [ 1164 | { 1165 | "name": "stdout", 1166 | "output_type": "stream", 1167 | "text": [ 1168 | "My name is Suresh, and I am 26\n" 1169 | ] 1170 | } 1171 | ], 1172 | "source": [ 1173 | "age = 26\n", 1174 | "txt = \"My name is Suresh, and I am {}\"\n", 1175 | "print (txt.format(age))" 1176 | ] 1177 | }, 1178 | { 1179 | "cell_type": "code", 1180 | "execution_count": 47, 1181 | "metadata": {}, 1182 | "outputs": [ 1183 | { 1184 | "name": "stdout", 1185 | "output_type": "stream", 1186 | "text": [ 1187 | "My name is Suresh, and I am 26 years old and I purchased 10 number of 3456\n" 1188 | ] 1189 | } 1190 | ], 1191 | "source": [ 1192 | "age = 26\n", 1193 | "quantity = 10\n", 1194 | "itemno = 3456\n", 1195 | "txt = \"My name is Suresh, and I am {} years old and I purchased {} number of {}\"\n", 1196 | "print (txt.format(age, quantity, itemno))" 1197 | ] 1198 | }, 1199 | { 1200 | "cell_type": "markdown", 1201 | "metadata": {}, 1202 | "source": [ 1203 | "##### Escape Character\n", 1204 | "\n", 1205 | "#### Common escape characters \n", 1206 | "\n", 1207 | "```\n", 1208 | "\\'\n", 1209 | "\\\"\n", 1210 | "\\n\n", 1211 | "\\t\n", 1212 | "\\b\n", 1213 | "\n", 1214 | "```" 1215 | ] 1216 | }, 1217 | { 1218 | "cell_type": "code", 1219 | "execution_count": 48, 1220 | "metadata": {}, 1221 | "outputs": [ 1222 | { 1223 | "data": { 1224 | "text/plain": [ 1225 | "'And then he said \"Hello World\"'" 1226 | ] 1227 | }, 1228 | "execution_count": 48, 1229 | "metadata": {}, 1230 | "output_type": "execute_result" 1231 | } 1232 | ], 1233 | "source": [ 1234 | "st = \"And then he said \\\"Hello World\\\"\"\n", 1235 | "st" 1236 | ] 1237 | }, 1238 | { 1239 | "cell_type": "code", 1240 | "execution_count": 49, 1241 | "metadata": {}, 1242 | "outputs": [ 1243 | { 1244 | "name": "stdout", 1245 | "output_type": "stream", 1246 | "text": [ 1247 | "And then he said\n", 1248 | " \"Hello World\"\n" 1249 | ] 1250 | } 1251 | ], 1252 | "source": [ 1253 | "st = \"And then he said\\n \\\"Hello World\\\"\"\n", 1254 | "print (st)" 1255 | ] 1256 | }, 1257 | { 1258 | "cell_type": "code", 1259 | "execution_count": 50, 1260 | "metadata": {}, 1261 | "outputs": [ 1262 | { 1263 | "name": "stdout", 1264 | "output_type": "stream", 1265 | "text": [ 1266 | "And then he said\t \"Hello World\"\n" 1267 | ] 1268 | } 1269 | ], 1270 | "source": [ 1271 | "st = \"And then he said\\t \\\"Hello World\\\"\"\n", 1272 | "print (st)" 1273 | ] 1274 | }, 1275 | { 1276 | "cell_type": "code", 1277 | "execution_count": 51, 1278 | "metadata": {}, 1279 | "outputs": [ 1280 | { 1281 | "name": "stdout", 1282 | "output_type": "stream", 1283 | "text": [ 1284 | "And then he said\b \"Hello World\"\n" 1285 | ] 1286 | } 1287 | ], 1288 | "source": [ 1289 | "st = \"And then he said\\b \\\"Hello World\\\"\"\n", 1290 | "print (st)" 1291 | ] 1292 | }, 1293 | { 1294 | "cell_type": "markdown", 1295 | "metadata": {}, 1296 | "source": [ 1297 | "##### Treasure hunt game example" 1298 | ] 1299 | }, 1300 | { 1301 | "cell_type": "markdown", 1302 | "metadata": {}, 1303 | "source": [ 1304 | "##### Tresure Hunt\n", 1305 | "\n", 1306 | "X -- is my treasure \n", 1307 | "1. If X index is found -- print he is the winner \n", 1308 | "2. if the guess is index of E - He is dead \n", 1309 | "3. if he guess other index(except E and X) # select other index \n", 1310 | "\n" 1311 | ] 1312 | }, 1313 | { 1314 | "cell_type": "code", 1315 | "execution_count": 53, 1316 | "metadata": {}, 1317 | "outputs": [ 1318 | { 1319 | "name": "stdout", 1320 | "output_type": "stream", 1321 | "text": [ 1322 | "Enter the number:::::5\n", 1323 | "Good try again. One clue is move towards left to win the game\n" 1324 | ] 1325 | } 1326 | ], 1327 | "source": [ 1328 | "guess=int(input(\"Enter the number:::::\"))\n", 1329 | "game_zone = ['','','','X','','','','E','','','','','','']\n", 1330 | "\n", 1331 | "success='X'\n", 1332 | "failure='E'\n", 1333 | "\n", 1334 | "while(guess >= 0):\n", 1335 | " if(guess <= len(game_zone)-1):\n", 1336 | " if (guess == game_zone.index(success)):\n", 1337 | " print(\"Congrats you are the winner\")\n", 1338 | " break\n", 1339 | " elif(guess == game_zone.index(failure)):\n", 1340 | " print(\"Sorry you lose!!! Better luck next time\")\n", 1341 | " break\n", 1342 | " elif(guess < game_zone.index(success)):\n", 1343 | " print(\"Good try again. One clue is move towards right to win the game\")\n", 1344 | " break\n", 1345 | " elif((guess > game_zone.index(success))):\n", 1346 | " print(\"Good try again. One clue is move towards left to win the game\")\n", 1347 | " break\n", 1348 | " else:\n", 1349 | " print(\"Better try from {f} to {l}\".format(f=0,l=len(game_zone)-1))\n", 1350 | " break\n", 1351 | " " 1352 | ] 1353 | }, 1354 | { 1355 | "cell_type": "markdown", 1356 | "metadata": {}, 1357 | "source": [ 1358 | "##### Wordcount\n", 1359 | "\n", 1360 | "Given a sentence, find how many times each word occured\n", 1361 | "\n", 1362 | "1. Convert everything to lowercase\n", 1363 | "1. Remove extra character (.)\n", 1364 | "1. Chunk into individual words\n", 1365 | "1. Read word by word and find the count, and store\n", 1366 | "1. Print" 1367 | ] 1368 | }, 1369 | { 1370 | "cell_type": "code", 1371 | "execution_count": 54, 1372 | "metadata": {}, 1373 | "outputs": [], 1374 | "source": [ 1375 | "sentence = \"\"\"Hello everybody I am learning Data Science. \n", 1376 | " I am learning about how to crunch large amount of data.\n", 1377 | " This helps us understand the past and predict the future\"\"\"\n", 1378 | "\n", 1379 | "# {'hello':1, 'data':2, 'i':2,.....}" 1380 | ] 1381 | }, 1382 | { 1383 | "cell_type": "code", 1384 | "execution_count": 55, 1385 | "metadata": {}, 1386 | "outputs": [ 1387 | { 1388 | "data": { 1389 | "text/plain": [ 1390 | "{'understand': 1,\n", 1391 | " 'and': 1,\n", 1392 | " 'this': 1,\n", 1393 | " 'predict': 1,\n", 1394 | " 'past': 1,\n", 1395 | " 'science': 1,\n", 1396 | " 'us': 1,\n", 1397 | " 'crunch': 1,\n", 1398 | " 'about': 1,\n", 1399 | " 'everybody': 1,\n", 1400 | " 'helps': 1,\n", 1401 | " 'data': 2,\n", 1402 | " 'how': 1,\n", 1403 | " 'future': 1,\n", 1404 | " 'amount': 1,\n", 1405 | " 'to': 1,\n", 1406 | " 'of': 1,\n", 1407 | " 'am': 2,\n", 1408 | " 'i': 2,\n", 1409 | " 'the': 2,\n", 1410 | " 'hello': 1,\n", 1411 | " 'learning': 2,\n", 1412 | " 'large': 1}" 1413 | ] 1414 | }, 1415 | "execution_count": 55, 1416 | "metadata": {}, 1417 | "output_type": "execute_result" 1418 | } 1419 | ], 1420 | "source": [ 1421 | "sentence = \"\"\"Hello everybody I am learning Data Science. \n", 1422 | " I am learning about how to crunch large amount of data.\n", 1423 | " This helps us understand the past and predict the future\"\"\"\n", 1424 | "\n", 1425 | "sentence = sentence.lower()\n", 1426 | "sentence = sentence.replace('.','')\n", 1427 | "sentence = sentence.replace('\\n','')\n", 1428 | "sentence_list = sentence.split(' ')\n", 1429 | "sentence_set = set(sentence_list)\n", 1430 | "\n", 1431 | "word_count = dict()\n", 1432 | "\n", 1433 | "for word in sentence_set:\n", 1434 | " if word == '':\n", 1435 | " continue\n", 1436 | " word_count[word] = sentence_list.count(word)\n", 1437 | "word_count" 1438 | ] 1439 | }, 1440 | { 1441 | "cell_type": "markdown", 1442 | "metadata": {}, 1443 | "source": [ 1444 | "##### Count Elements in a List without using inbuilt function\n", 1445 | "\n", 1446 | "Given a list of integers, and a number num, find how many times num is present in integers" 1447 | ] 1448 | }, 1449 | { 1450 | "cell_type": "code", 1451 | "execution_count": 56, 1452 | "metadata": {}, 1453 | "outputs": [ 1454 | { 1455 | "name": "stdout", 1456 | "output_type": "stream", 1457 | "text": [ 1458 | "Enter number to be searched: 5\n", 1459 | "number of times number 4\n" 1460 | ] 1461 | } 1462 | ], 1463 | "source": [ 1464 | "lst = [3,4,6,5,7,5,4,5,6,7,5,4]\n", 1465 | "\n", 1466 | "num = int(input('Enter number to be searched: ')) \n", 1467 | "\n", 1468 | "counter = 0\n", 1469 | "for item in lst:\n", 1470 | " if num == item:\n", 1471 | " counter += 1\n", 1472 | "print (\"number of times number\",counter)" 1473 | ] 1474 | } 1475 | ], 1476 | "metadata": { 1477 | "kernelspec": { 1478 | "display_name": "Python 3 (ipykernel)", 1479 | "language": "python", 1480 | "name": "python3" 1481 | }, 1482 | "language_info": { 1483 | "codemirror_mode": { 1484 | "name": "ipython", 1485 | "version": 3 1486 | }, 1487 | "file_extension": ".py", 1488 | "mimetype": "text/x-python", 1489 | "name": "python", 1490 | "nbconvert_exporter": "python", 1491 | "pygments_lexer": "ipython3", 1492 | "version": "3.9.7" 1493 | } 1494 | }, 1495 | "nbformat": 4, 1496 | "nbformat_minor": 2 1497 | } 1498 | -------------------------------------------------------------------------------- /Functions.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "##### Functions\n", 8 | "\n", 9 | "A function is a block of organized, reusable code that is used to perform a single, related action. ... Different programming languages name them differently, for example, functions, methods, sub-routines, procedures, etc.\n", 10 | "\n", 11 | "\n", 12 | "## Advantages:\n", 13 | "\n", 14 | "- Makes your code more organized and manageable.\n", 15 | "- Brings code reusability.\n", 16 | "\n", 17 | "## Function Syantax:\n", 18 | "```\n", 19 | "def ([parameters]):\n", 20 | " '''Doc string'''\n", 21 | " Logic/statements\n", 22 | " ...\n", 23 | " ...\n", 24 | " return value/print(value)\n", 25 | "```\n", 26 | "**def** - marks the start of the function header.\\\n", 27 | "**function name** - a unique name to idenfity the function, this naming follows the same checklist we learnt in variable naming.\\\n", 28 | "**parameters/arguments** - used to pass a value to the function while calling. These are optional.\\\n", 29 | "**Doc String** - a short description about the function. This is optional.\\\n", 30 | "**Logic/statements** - one or more valid python statements to perform the required task.\\\n", 31 | "**retrun** - this will return a value from the funxtion. Optional.\\\n", 32 | "**print** - to display a value from the fucntion. Optional.\n" 33 | ] 34 | }, 35 | { 36 | "cell_type": "code", 37 | "execution_count": 1, 38 | "metadata": {}, 39 | "outputs": [], 40 | "source": [ 41 | "# defining a fuction\n", 42 | "def summ(a,b):\n", 43 | " c=a+b\n", 44 | " #print(c)\n", 45 | " return(c)" 46 | ] 47 | }, 48 | { 49 | "cell_type": "code", 50 | "execution_count": 2, 51 | "metadata": {}, 52 | "outputs": [ 53 | { 54 | "data": { 55 | "text/plain": [ 56 | "30" 57 | ] 58 | }, 59 | "execution_count": 2, 60 | "metadata": {}, 61 | "output_type": "execute_result" 62 | } 63 | ], 64 | "source": [ 65 | "# Calling a function\n", 66 | "summ(10,20)" 67 | ] 68 | }, 69 | { 70 | "cell_type": "code", 71 | "execution_count": 3, 72 | "metadata": {}, 73 | "outputs": [ 74 | { 75 | "name": "stdout", 76 | "output_type": "stream", 77 | "text": [ 78 | "30\n" 79 | ] 80 | } 81 | ], 82 | "source": [ 83 | "result=summ(10,20)\n", 84 | "print(result)" 85 | ] 86 | }, 87 | { 88 | "cell_type": "markdown", 89 | "metadata": {}, 90 | "source": [ 91 | "##### function Arguments\n", 92 | "1. Required Argumnents \n", 93 | "2. Keyword Argumnents \n", 94 | "3. Default Argumenst \n", 95 | "4. Variable length Argumnents\n" 96 | ] 97 | }, 98 | { 99 | "cell_type": "code", 100 | "execution_count": 4, 101 | "metadata": { 102 | "colab": { 103 | "base_uri": "https://localhost:8080/", 104 | "height": 34 105 | }, 106 | "id": "mehb1BXLO2Kf", 107 | "outputId": "374913da-9059-4171-d45d-1e7497c31259" 108 | }, 109 | "outputs": [ 110 | { 111 | "data": { 112 | "text/plain": [ 113 | "30" 114 | ] 115 | }, 116 | "execution_count": 4, 117 | "metadata": {}, 118 | "output_type": "execute_result" 119 | } 120 | ], 121 | "source": [ 122 | "# Required Arguments \n", 123 | "summ(10,20)" 124 | ] 125 | }, 126 | { 127 | "cell_type": "code", 128 | "execution_count": 5, 129 | "metadata": { 130 | "colab": { 131 | "base_uri": "https://localhost:8080/", 132 | "height": 34 133 | }, 134 | "id": "kfajV2hlO8sp", 135 | "outputId": "3e2ed063-7183-41be-bae3-68de34d6c8ed" 136 | }, 137 | "outputs": [ 138 | { 139 | "data": { 140 | "text/plain": [ 141 | "30" 142 | ] 143 | }, 144 | "execution_count": 5, 145 | "metadata": {}, 146 | "output_type": "execute_result" 147 | } 148 | ], 149 | "source": [ 150 | "# keyword Arguments\n", 151 | "summ(b=10,a=20)" 152 | ] 153 | }, 154 | { 155 | "cell_type": "code", 156 | "execution_count": 6, 157 | "metadata": { 158 | "id": "Y_nrwwWPPC0Y" 159 | }, 160 | "outputs": [], 161 | "source": [ 162 | "# Default Arguments\n", 163 | "def printinfo( name,age = 35 ):\n", 164 | " #\"This prints a passed info into this function\"\n", 165 | " print (\"Name: \", name)\n", 166 | " print (\"Age \", age)\n", 167 | " return;" 168 | ] 169 | }, 170 | { 171 | "cell_type": "code", 172 | "execution_count": 7, 173 | "metadata": { 174 | "colab": { 175 | "base_uri": "https://localhost:8080/", 176 | "height": 51 177 | }, 178 | "id": "9lqWUEv0UHgu", 179 | "outputId": "9659dc6d-bbd1-4e79-b930-8efc6d927ac4" 180 | }, 181 | "outputs": [ 182 | { 183 | "name": "stdout", 184 | "output_type": "stream", 185 | "text": [ 186 | "Name: Data Science\n", 187 | "Age 35\n" 188 | ] 189 | } 190 | ], 191 | "source": [ 192 | "printinfo(\"Data Science\")\n" 193 | ] 194 | }, 195 | { 196 | "cell_type": "code", 197 | "execution_count": 8, 198 | "metadata": { 199 | "colab": { 200 | "base_uri": "https://localhost:8080/", 201 | "height": 51 202 | }, 203 | "id": "ce8eKkxCPJPL", 204 | "outputId": "63f15611-101d-44be-cb1f-41ecb80a1043" 205 | }, 206 | "outputs": [ 207 | { 208 | "name": "stdout", 209 | "output_type": "stream", 210 | "text": [ 211 | "Name: Data Science\n", 212 | "Age 50\n" 213 | ] 214 | } 215 | ], 216 | "source": [ 217 | "printinfo(\"Data Science\",50)\n" 218 | ] 219 | }, 220 | { 221 | "cell_type": "code", 222 | "execution_count": 9, 223 | "metadata": { 224 | "id": "A6ZRqiI9PMkn" 225 | }, 226 | "outputs": [ 227 | { 228 | "name": "stdout", 229 | "output_type": "stream", 230 | "text": [ 231 | "Name: Data Science\n", 232 | "Age 35\n" 233 | ] 234 | } 235 | ], 236 | "source": [ 237 | "printinfo(\"Data Science\") # Age is assumed to be a default Argument " 238 | ] 239 | }, 240 | { 241 | "cell_type": "code", 242 | "execution_count": 15, 243 | "metadata": { 244 | "id": "vW4K97olPQbq" 245 | }, 246 | "outputs": [], 247 | "source": [ 248 | "# Variable Length Arguments\n", 249 | "def varlen( arg1, *vartuple ):\n", 250 | " \n", 251 | " print (\"Output is: \")\n", 252 | " print (\"arg1 is:\",arg1)\n", 253 | " # for var in vartuple:\n", 254 | " print(\"Var tuple is:\",vartuple)\n", 255 | " return vartuple*2\n", 256 | " " 257 | ] 258 | }, 259 | { 260 | "cell_type": "code", 261 | "execution_count": 16, 262 | "metadata": { 263 | "colab": { 264 | "base_uri": "https://localhost:8080/", 265 | "height": 68 266 | }, 267 | "id": "EBRCC5cEPbEM", 268 | "outputId": "535bebc4-7065-4938-d641-39620938d32e", 269 | "scrolled": true 270 | }, 271 | "outputs": [ 272 | { 273 | "name": "stdout", 274 | "output_type": "stream", 275 | "text": [ 276 | "Output is: \n", 277 | "arg1 is: 10\n", 278 | "Var tuple is: (1, 2, 3, 4, 5)\n" 279 | ] 280 | }, 281 | { 282 | "data": { 283 | "text/plain": [ 284 | "(1, 2, 3, 4, 5, 1, 2, 3, 4, 5)" 285 | ] 286 | }, 287 | "execution_count": 16, 288 | "metadata": {}, 289 | "output_type": "execute_result" 290 | } 291 | ], 292 | "source": [ 293 | "varlen(10,1,2,3,4,5)" 294 | ] 295 | }, 296 | { 297 | "cell_type": "markdown", 298 | "metadata": {}, 299 | "source": [ 300 | "##### Keyword Arguments - kwarg" 301 | ] 302 | }, 303 | { 304 | "cell_type": "code", 305 | "execution_count": 17, 306 | "metadata": {}, 307 | "outputs": [ 308 | { 309 | "name": "stdout", 310 | "output_type": "stream", 311 | "text": [ 312 | "var value\n", 313 | "{'a': 1, 'b': 2}\n" 314 | ] 315 | } 316 | ], 317 | "source": [ 318 | "def func(var, **kwarg):\n", 319 | " print (var)\n", 320 | " print (kwarg)\n", 321 | "\n", 322 | "# func()\n", 323 | "func('var value', a=1,b=2)" 324 | ] 325 | }, 326 | { 327 | "cell_type": "markdown", 328 | "metadata": { 329 | "id": "-9VYCnIXIwiS" 330 | }, 331 | "source": [ 332 | "#### Lambda Fucntion(Ananymous)\n", 333 | "Lambda functions are used when you need a function for a short period of time. This is commonly used when you want to pass a function as an argument to higher-order functions, that is, functions that take other functions as their arguments.\n", 334 | "* Syntax: lambda [arg1 [,arg2,.....argn]]:expression" 335 | ] 336 | }, 337 | { 338 | "cell_type": "code", 339 | "execution_count": 18, 340 | "metadata": { 341 | "colab": { 342 | "base_uri": "https://localhost:8080/", 343 | "height": 34 344 | }, 345 | "id": "OPyDq6ZqRAER", 346 | "outputId": "5c1f20fe-f5d3-45dc-e5a9-8f2815b3ae50" 347 | }, 348 | "outputs": [ 349 | { 350 | "data": { 351 | "text/plain": [ 352 | "30" 353 | ] 354 | }, 355 | "execution_count": 18, 356 | "metadata": {}, 357 | "output_type": "execute_result" 358 | } 359 | ], 360 | "source": [ 361 | "def add(x, y):\n", 362 | " return x + y\n", 363 | "\n", 364 | "add(10,20)" 365 | ] 366 | }, 367 | { 368 | "cell_type": "code", 369 | "execution_count": 19, 370 | "metadata": {}, 371 | "outputs": [ 372 | { 373 | "data": { 374 | "text/plain": [ 375 | "30" 376 | ] 377 | }, 378 | "execution_count": 19, 379 | "metadata": {}, 380 | "output_type": "execute_result" 381 | } 382 | ], 383 | "source": [ 384 | "(lambda x, y: x + y)(10, 20)" 385 | ] 386 | }, 387 | { 388 | "cell_type": "markdown", 389 | "metadata": {}, 390 | "source": [ 391 | "##### Filter Functions\n", 392 | "Filter() function takes a function as the first argument and the list as the second argument to which we want to apply a filtering function" 393 | ] 394 | }, 395 | { 396 | "cell_type": "code", 397 | "execution_count": 20, 398 | "metadata": {}, 399 | "outputs": [ 400 | { 401 | "name": "stdout", 402 | "output_type": "stream", 403 | "text": [ 404 | "[4, 6, 8, 12]\n" 405 | ] 406 | } 407 | ], 408 | "source": [ 409 | "my_list = [1, 5, 4, 6, 8, 11, 3, 12]\n", 410 | "\n", 411 | "new_list = list(filter(lambda x: (x%2 == 0) , my_list))\n", 412 | "print(new_list)\n" 413 | ] 414 | }, 415 | { 416 | "cell_type": "markdown", 417 | "metadata": {}, 418 | "source": [ 419 | "##### Map and Reduce Functions\n", 420 | "Map applies a function to all the items in an input_list.\n", 421 | "\n", 422 | "map(function_to_apply, list_of_inputs)" 423 | ] 424 | }, 425 | { 426 | "cell_type": "code", 427 | "execution_count": 21, 428 | "metadata": {}, 429 | "outputs": [ 430 | { 431 | "data": { 432 | "text/plain": [ 433 | "[1, 4, 9, 16, 25]" 434 | ] 435 | }, 436 | "execution_count": 21, 437 | "metadata": {}, 438 | "output_type": "execute_result" 439 | } 440 | ], 441 | "source": [ 442 | "def square_all_numbers(numb_list):\n", 443 | " results = []\n", 444 | " for num in numb_list:\n", 445 | " results.append(num**2)\n", 446 | " return results\n", 447 | "square_all_numbers([1,2,3,4,5])" 448 | ] 449 | }, 450 | { 451 | "cell_type": "code", 452 | "execution_count": 22, 453 | "metadata": {}, 454 | "outputs": [ 455 | { 456 | "name": "stdout", 457 | "output_type": "stream", 458 | "text": [ 459 | "[1, 4, 9, 16, 25]\n" 460 | ] 461 | } 462 | ], 463 | "source": [ 464 | "items = [1, 2, 3, 4, 5]\n", 465 | "squared = list(map(lambda x: x**2, items))\n", 466 | "print (squared)" 467 | ] 468 | }, 469 | { 470 | "cell_type": "markdown", 471 | "metadata": {}, 472 | "source": [ 473 | "##### Reduce is a really useful function for performing some computation on a list and returning the result. It applies a rolling computation to sequential pairs of values in a list. For example, if you wanted to compute the product of a list of integers." 474 | ] 475 | }, 476 | { 477 | "cell_type": "code", 478 | "execution_count": 23, 479 | "metadata": {}, 480 | "outputs": [ 481 | { 482 | "name": "stdout", 483 | "output_type": "stream", 484 | "text": [ 485 | "120\n" 486 | ] 487 | } 488 | ], 489 | "source": [ 490 | "product = 1\n", 491 | "lst = [1, 2, 3, 4, 5]\n", 492 | "for num in lst:\n", 493 | " product = product * num\n", 494 | "print (product)" 495 | ] 496 | }, 497 | { 498 | "cell_type": "code", 499 | "execution_count": 24, 500 | "metadata": {}, 501 | "outputs": [ 502 | { 503 | "data": { 504 | "text/plain": [ 505 | "120" 506 | ] 507 | }, 508 | "execution_count": 24, 509 | "metadata": {}, 510 | "output_type": "execute_result" 511 | } 512 | ], 513 | "source": [ 514 | "from functools import reduce\n", 515 | "\n", 516 | "product = reduce((lambda x, y: x * y), [1, 2, 3, 4, 5])\n", 517 | "product" 518 | ] 519 | }, 520 | { 521 | "cell_type": "markdown", 522 | "metadata": { 523 | "id": "QIDCrIekI4RL" 524 | }, 525 | "source": [ 526 | "#### Recursive Function\n", 527 | "* Function Calling a function itself" 528 | ] 529 | }, 530 | { 531 | "cell_type": "code", 532 | "execution_count": 25, 533 | "metadata": { 534 | "id": "Kt2z6XvNRfVo" 535 | }, 536 | "outputs": [], 537 | "source": [ 538 | "# Normal function to alculat factorial\n", 539 | "#n=1\n", 540 | "def fact(n):\n", 541 | " \n", 542 | " if(n<0):\n", 543 | " return(\"enter valid n value\")\n", 544 | " \n", 545 | " if(n==1 or n==0 ): \n", 546 | " return 1\n", 547 | " \n", 548 | " else:\n", 549 | " for i in range(1,n): \n", 550 | " n=n*i\n", 551 | " return(n)" 552 | ] 553 | }, 554 | { 555 | "cell_type": "code", 556 | "execution_count": 26, 557 | "metadata": { 558 | "colab": { 559 | "base_uri": "https://localhost:8080/", 560 | "height": 34 561 | }, 562 | "id": "wLdyicllRkWF", 563 | "outputId": "2c82861c-ae37-446b-860e-72837b3c79f6" 564 | }, 565 | "outputs": [ 566 | { 567 | "data": { 568 | "text/plain": [ 569 | "120" 570 | ] 571 | }, 572 | "execution_count": 26, 573 | "metadata": {}, 574 | "output_type": "execute_result" 575 | } 576 | ], 577 | "source": [ 578 | "fact(5)" 579 | ] 580 | }, 581 | { 582 | "cell_type": "code", 583 | "execution_count": 27, 584 | "metadata": { 585 | "id": "lurv2xG4RjHf" 586 | }, 587 | "outputs": [], 588 | "source": [ 589 | "# Recursive function to calculate Factorial ofthe number\n", 590 | "def rec_fact(n):\n", 591 | " if(n==1 or n==0):\n", 592 | " return 1\n", 593 | " else:\n", 594 | " fact=n*rec_fact(n-1)\n", 595 | " \n", 596 | " return(fact)" 597 | ] 598 | }, 599 | { 600 | "cell_type": "code", 601 | "execution_count": 28, 602 | "metadata": { 603 | "colab": { 604 | "base_uri": "https://localhost:8080/", 605 | "height": 34 606 | }, 607 | "id": "q1uh1WSXRlT_", 608 | "outputId": "f1443ce5-4c97-462c-be5d-8a14126a650a" 609 | }, 610 | "outputs": [ 611 | { 612 | "data": { 613 | "text/plain": [ 614 | "120" 615 | ] 616 | }, 617 | "execution_count": 28, 618 | "metadata": {}, 619 | "output_type": "execute_result" 620 | } 621 | ], 622 | "source": [ 623 | "rec_fact(5)" 624 | ] 625 | }, 626 | { 627 | "cell_type": "markdown", 628 | "metadata": { 629 | "id": "JMpgpNiqRt9x" 630 | }, 631 | "source": [ 632 | "# Scope of variables\n", 633 | "* Global Variable\n", 634 | "* Local Variable" 635 | ] 636 | }, 637 | { 638 | "cell_type": "code", 639 | "execution_count": 29, 640 | "metadata": { 641 | "id": "cS2-H1xaR3QL" 642 | }, 643 | "outputs": [], 644 | "source": [ 645 | "# Local Variable and Global Variable\n", 646 | "#print(global_var)\n", 647 | "global_var=100 # Global Variable\n", 648 | "def Function(a):\n", 649 | " loc_var=10 # Local Varaible\n", 650 | " print(\"Local Varible\",loc_var)\n", 651 | " print(\"Gloabal Varible\",global_var)" 652 | ] 653 | }, 654 | { 655 | "cell_type": "code", 656 | "execution_count": 30, 657 | "metadata": { 658 | "colab": { 659 | "base_uri": "https://localhost:8080/", 660 | "height": 34 661 | }, 662 | "id": "xrAogpDKR60K", 663 | "outputId": "9423d990-a97f-4f5e-f8b7-31fc4fd848b4" 664 | }, 665 | "outputs": [ 666 | { 667 | "name": "stdout", 668 | "output_type": "stream", 669 | "text": [ 670 | "Local Varible 10\n", 671 | "Gloabal Varible 100\n" 672 | ] 673 | } 674 | ], 675 | "source": [ 676 | "Function(10)" 677 | ] 678 | }, 679 | { 680 | "cell_type": "code", 681 | "execution_count": 31, 682 | "metadata": { 683 | "colab": { 684 | "base_uri": "https://localhost:8080/", 685 | "height": 34 686 | }, 687 | "id": "MvOqGnJSSgPT", 688 | "outputId": "5464f462-edba-4c85-f752-aaaab472f78e" 689 | }, 690 | "outputs": [ 691 | { 692 | "name": "stdout", 693 | "output_type": "stream", 694 | "text": [ 695 | "100\n" 696 | ] 697 | } 698 | ], 699 | "source": [ 700 | "\n", 701 | "print(global_var)" 702 | ] 703 | }, 704 | { 705 | "cell_type": "code", 706 | "execution_count": 32, 707 | "metadata": { 708 | "colab": { 709 | "base_uri": "https://localhost:8080/", 710 | "height": 163 711 | }, 712 | "id": "fuJuG33ASSjt", 713 | "outputId": "7233487c-2010-4eb8-861d-8bf787d264a9" 714 | }, 715 | "outputs": [ 716 | { 717 | "ename": "NameError", 718 | "evalue": "name 'loc_var' is not defined", 719 | "output_type": "error", 720 | "traceback": [ 721 | "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", 722 | "\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)", 723 | "\u001b[1;32mC:\\WINDOWS\\TEMP/ipykernel_14172/456088440.py\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mloc_var\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;31m# Scope of this varaible is within fuction only\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", 724 | "\u001b[1;31mNameError\u001b[0m: name 'loc_var' is not defined" 725 | ] 726 | } 727 | ], 728 | "source": [ 729 | "print(loc_var) # Scope of this varaible is within fuction only" 730 | ] 731 | }, 732 | { 733 | "cell_type": "code", 734 | "execution_count": 34, 735 | "metadata": { 736 | "colab": { 737 | "base_uri": "https://localhost:8080/", 738 | "height": 34 739 | }, 740 | "id": "zgUFds3ZR6pG", 741 | "outputId": "8d2f7086-70a1-4a11-aa29-32fab274089f", 742 | "scrolled": false 743 | }, 744 | "outputs": [ 745 | { 746 | "name": "stdout", 747 | "output_type": "stream", 748 | "text": [ 749 | "100\n" 750 | ] 751 | } 752 | ], 753 | "source": [ 754 | "print(global_var) # Scope of this is outside the function also" 755 | ] 756 | }, 757 | { 758 | "cell_type": "code", 759 | "execution_count": 35, 760 | "metadata": {}, 761 | "outputs": [], 762 | "source": [ 763 | "\n", 764 | "def function():\n", 765 | " global local_variable # Make a local variable as gloabl\n", 766 | " local_variable=10\n", 767 | " print(local_variable)\n" 768 | ] 769 | }, 770 | { 771 | "cell_type": "code", 772 | "execution_count": 36, 773 | "metadata": {}, 774 | "outputs": [ 775 | { 776 | "name": "stdout", 777 | "output_type": "stream", 778 | "text": [ 779 | "10\n" 780 | ] 781 | } 782 | ], 783 | "source": [ 784 | "function()" 785 | ] 786 | }, 787 | { 788 | "cell_type": "code", 789 | "execution_count": 37, 790 | "metadata": {}, 791 | "outputs": [ 792 | { 793 | "name": "stdout", 794 | "output_type": "stream", 795 | "text": [ 796 | "10\n" 797 | ] 798 | } 799 | ], 800 | "source": [ 801 | "print(local_variable)" 802 | ] 803 | } 804 | ], 805 | "metadata": { 806 | "kernelspec": { 807 | "display_name": "Python 3 (ipykernel)", 808 | "language": "python", 809 | "name": "python3" 810 | }, 811 | "language_info": { 812 | "codemirror_mode": { 813 | "name": "ipython", 814 | "version": 3 815 | }, 816 | "file_extension": ".py", 817 | "mimetype": "text/x-python", 818 | "name": "python", 819 | "nbconvert_exporter": "python", 820 | "pygments_lexer": "ipython3", 821 | "version": "3.9.7" 822 | } 823 | }, 824 | "nbformat": 4, 825 | "nbformat_minor": 4 826 | } 827 | -------------------------------------------------------------------------------- /Python_basics.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "colab_type": "text", 7 | "id": "view-in-github" 8 | }, 9 | "source": [ 10 | "\"Open" 11 | ] 12 | }, 13 | { 14 | "cell_type": "markdown", 15 | "metadata": { 16 | "id": "JbVT11Y8CbAu" 17 | }, 18 | "source": [ 19 | "# Welcome" 20 | ] 21 | }, 22 | { 23 | "cell_type": "markdown", 24 | "metadata": { 25 | "id": "kw1B2R_WCU7X" 26 | }, 27 | "source": [ 28 | "Welcome to the first practical work of the week! In this practical, we will learn about the programming language Python as well as NumPy and Matplotlib, two fundamental tools for data science and machine learning in Python." 29 | ] 30 | }, 31 | { 32 | "cell_type": "markdown", 33 | "metadata": { 34 | "id": "qyLSwlxnJqXX" 35 | }, 36 | "source": [ 37 | "# Python" 38 | ] 39 | }, 40 | { 41 | "cell_type": "markdown", 42 | "metadata": { 43 | "id": "3ltwm91eJyQM" 44 | }, 45 | "source": [ 46 | "Python is one of the most popular programming languages for machine learning, both in academia and in industry. As such, it is essential to learn this language for anyone interested in machine learning. In this section, we will review Python basics." 47 | ] 48 | }, 49 | { 50 | "cell_type": "code", 51 | "execution_count": 1, 52 | "metadata": { 53 | "colab": { 54 | "base_uri": "https://localhost:8080/" 55 | }, 56 | "id": "qeGAvLq1ALJ4", 57 | "outputId": "775c9da1-aa9c-43df-d6d4-500f1dda2d63" 58 | }, 59 | "outputs": [ 60 | { 61 | "data": { 62 | "text/plain": [ 63 | "86400" 64 | ] 65 | }, 66 | "execution_count": 1, 67 | "metadata": {}, 68 | "output_type": "execute_result" 69 | } 70 | ], 71 | "source": [ 72 | "seconds_in_a_day = 24 * 60 * 60\n", 73 | "seconds_in_a_day" 74 | ] 75 | }, 76 | { 77 | "cell_type": "code", 78 | "execution_count": null, 79 | "metadata": { 80 | "colab": { 81 | "base_uri": "https://localhost:8080/", 82 | "height": 34 83 | }, 84 | "id": "s1kp5Zv0JBSx", 85 | "outputId": "5c3d203f-046d-4555-d398-36e91dbe685c" 86 | }, 87 | "outputs": [ 88 | { 89 | "data": { 90 | "text/plain": [ 91 | "604800" 92 | ] 93 | }, 94 | "execution_count": 20, 95 | "metadata": { 96 | "tags": [] 97 | }, 98 | "output_type": "execute_result" 99 | } 100 | ], 101 | "source": [ 102 | "seconds_in_a_week = 7 * seconds_in_a_day\n", 103 | "seconds_in_a_week" 104 | ] 105 | }, 106 | { 107 | "cell_type": "markdown", 108 | "metadata": { 109 | "id": "3EKvP6jiMZ9H" 110 | }, 111 | "source": [ 112 | "## Arithmetic operations" 113 | ] 114 | }, 115 | { 116 | "cell_type": "markdown", 117 | "metadata": { 118 | "id": "DDjs0-7YQ80h" 119 | }, 120 | "source": [ 121 | "Python supports the usual arithmetic operators: + (addition), * (multiplication), / (division), ** (power), // (integer division)." 122 | ] 123 | }, 124 | { 125 | "cell_type": "markdown", 126 | "metadata": { 127 | "id": "UhcbBQUiStHG" 128 | }, 129 | "source": [ 130 | "## Lists" 131 | ] 132 | }, 133 | { 134 | "cell_type": "markdown", 135 | "metadata": { 136 | "id": "RkPn1IjNTCxA" 137 | }, 138 | "source": [ 139 | "Lists are a container type for ordered sequences of elements. Lists can be initialized empty" 140 | ] 141 | }, 142 | { 143 | "cell_type": "code", 144 | "execution_count": null, 145 | "metadata": { 146 | "id": "OrnV1ySAPtHp" 147 | }, 148 | "outputs": [], 149 | "source": [ 150 | "my_list = []" 151 | ] 152 | }, 153 | { 154 | "cell_type": "markdown", 155 | "metadata": { 156 | "id": "OwRqyYI9XnPK" 157 | }, 158 | "source": [ 159 | "or with some initial elements" 160 | ] 161 | }, 162 | { 163 | "cell_type": "code", 164 | "execution_count": null, 165 | "metadata": { 166 | "id": "Uq5YTJ1JXpOX" 167 | }, 168 | "outputs": [], 169 | "source": [ 170 | "my_list = [1, 2, 3]" 171 | ] 172 | }, 173 | { 174 | "cell_type": "markdown", 175 | "metadata": { 176 | "id": "Hk2WmojJXyyz" 177 | }, 178 | "source": [ 179 | "Lists have a dynamic size and elements can be added (appended) to them" 180 | ] 181 | }, 182 | { 183 | "cell_type": "code", 184 | "execution_count": null, 185 | "metadata": { 186 | "colab": { 187 | "base_uri": "https://localhost:8080/", 188 | "height": 34 189 | }, 190 | "id": "QFTNqiYiXxAh", 191 | "outputId": "720d3340-7df7-49b8-c920-964d2e350af5" 192 | }, 193 | "outputs": [ 194 | { 195 | "data": { 196 | "text/plain": [ 197 | "[1, 2, 3, 4]" 198 | ] 199 | }, 200 | "execution_count": 9, 201 | "metadata": { 202 | "tags": [] 203 | }, 204 | "output_type": "execute_result" 205 | } 206 | ], 207 | "source": [ 208 | "my_list.append(4)\n", 209 | "my_list" 210 | ] 211 | }, 212 | { 213 | "cell_type": "markdown", 214 | "metadata": { 215 | "id": "IUnJuqQ2Yhzw" 216 | }, 217 | "source": [ 218 | "We can access individual elements of a list (indexing starts from 0)" 219 | ] 220 | }, 221 | { 222 | "cell_type": "code", 223 | "execution_count": null, 224 | "metadata": { 225 | "colab": { 226 | "base_uri": "https://localhost:8080/", 227 | "height": 34 228 | }, 229 | "id": "pyFxyZPVYpG_", 230 | "outputId": "7efb0bc1-25fb-4849-8d3a-cfa62b94a175" 231 | }, 232 | "outputs": [ 233 | { 234 | "data": { 235 | "text/plain": [ 236 | "3" 237 | ] 238 | }, 239 | "execution_count": 10, 240 | "metadata": { 241 | "tags": [] 242 | }, 243 | "output_type": "execute_result" 244 | } 245 | ], 246 | "source": [ 247 | "my_list[2]" 248 | ] 249 | }, 250 | { 251 | "cell_type": "markdown", 252 | "metadata": { 253 | "id": "hPMrIDYsdgMP" 254 | }, 255 | "source": [ 256 | "We can access \"slices\" of a list using `my_list[i:j]` where `i` is the start of the slice (again, indexing starts from 0) and `j` the end of the slice. For instance:" 257 | ] 258 | }, 259 | { 260 | "cell_type": "code", 261 | "execution_count": null, 262 | "metadata": { 263 | "colab": { 264 | "base_uri": "https://localhost:8080/", 265 | "height": 34 266 | }, 267 | "id": "Ichf9p0gd7tJ", 268 | "outputId": "5f4ec085-431e-4e16-aab1-8708f2c931d4" 269 | }, 270 | "outputs": [ 271 | { 272 | "data": { 273 | "text/plain": [ 274 | "[2, 3]" 275 | ] 276 | }, 277 | "execution_count": 14, 278 | "metadata": { 279 | "tags": [] 280 | }, 281 | "output_type": "execute_result" 282 | } 283 | ], 284 | "source": [ 285 | "my_list[1:3]" 286 | ] 287 | }, 288 | { 289 | "cell_type": "markdown", 290 | "metadata": { 291 | "id": "KMbzH4tzQ9rI" 292 | }, 293 | "source": [ 294 | "Omitting the second index means that the slice shoud run until the end of the list" 295 | ] 296 | }, 297 | { 298 | "cell_type": "code", 299 | "execution_count": null, 300 | "metadata": { 301 | "colab": { 302 | "base_uri": "https://localhost:8080/", 303 | "height": 34 304 | }, 305 | "id": "O7wCthKnREKV", 306 | "outputId": "5a04ea59-7a54-4b09-a8ee-3cd6171e8c7a" 307 | }, 308 | "outputs": [ 309 | { 310 | "data": { 311 | "text/plain": [ 312 | "[2, 3, 4]" 313 | ] 314 | }, 315 | "execution_count": 64, 316 | "metadata": { 317 | "tags": [] 318 | }, 319 | "output_type": "execute_result" 320 | } 321 | ], 322 | "source": [ 323 | "my_list[1:]" 324 | ] 325 | }, 326 | { 327 | "cell_type": "markdown", 328 | "metadata": { 329 | "id": "C5Aeu7PUebrK" 330 | }, 331 | "source": [ 332 | "We can check if an element is in the list using `in`" 333 | ] 334 | }, 335 | { 336 | "cell_type": "code", 337 | "execution_count": null, 338 | "metadata": { 339 | "colab": { 340 | "base_uri": "https://localhost:8080/", 341 | "height": 34 342 | }, 343 | "id": "a_P5NCi-efvb", 344 | "outputId": "5012122e-f02c-4474-ec51-6ef8519e5733" 345 | }, 346 | "outputs": [ 347 | { 348 | "data": { 349 | "text/plain": [ 350 | "False" 351 | ] 352 | }, 353 | "execution_count": 15, 354 | "metadata": { 355 | "tags": [] 356 | }, 357 | "output_type": "execute_result" 358 | } 359 | ], 360 | "source": [ 361 | "5 in my_list" 362 | ] 363 | }, 364 | { 365 | "cell_type": "markdown", 366 | "metadata": { 367 | "id": "LypIsP5gkl10" 368 | }, 369 | "source": [ 370 | "The length of a list can be obtained using the `len` function" 371 | ] 372 | }, 373 | { 374 | "cell_type": "code", 375 | "execution_count": null, 376 | "metadata": { 377 | "colab": { 378 | "base_uri": "https://localhost:8080/", 379 | "height": 34 380 | }, 381 | "id": "ac0FMsaKkrWc", 382 | "outputId": "0a7418d2-67a1-419c-e12b-e6ffb3b4b66d" 383 | }, 384 | "outputs": [ 385 | { 386 | "data": { 387 | "text/plain": [ 388 | "4" 389 | ] 390 | }, 391 | "execution_count": 24, 392 | "metadata": { 393 | "tags": [] 394 | }, 395 | "output_type": "execute_result" 396 | } 397 | ], 398 | "source": [ 399 | "len(my_list)" 400 | ] 401 | }, 402 | { 403 | "cell_type": "markdown", 404 | "metadata": { 405 | "id": "1c3RLStf7G2I" 406 | }, 407 | "source": [ 408 | "## Strings" 409 | ] 410 | }, 411 | { 412 | "cell_type": "markdown", 413 | "metadata": { 414 | "id": "Jm6hZhgz7KhI" 415 | }, 416 | "source": [ 417 | "Strings are used to store text. They can delimited using either single quotes or double quotes" 418 | ] 419 | }, 420 | { 421 | "cell_type": "code", 422 | "execution_count": null, 423 | "metadata": { 424 | "id": "cCma6Oj_7T8n" 425 | }, 426 | "outputs": [], 427 | "source": [ 428 | "string1 = \"some text\"\n", 429 | "string2 = 'some other text'" 430 | ] 431 | }, 432 | { 433 | "cell_type": "markdown", 434 | "metadata": { 435 | "id": "Irr4xuWu7Znu" 436 | }, 437 | "source": [ 438 | "Strings behave similarly to lists. As such we can access individual elements in exactly the same way" 439 | ] 440 | }, 441 | { 442 | "cell_type": "code", 443 | "execution_count": null, 444 | "metadata": { 445 | "colab": { 446 | "base_uri": "https://localhost:8080/", 447 | "height": 35 448 | }, 449 | "id": "26_POhLO7iM3", 450 | "outputId": "fa06d3b9-c683-4b05-bedc-36bc43f57bd4" 451 | }, 452 | "outputs": [ 453 | { 454 | "data": { 455 | "application/vnd.google.colaboratory.intrinsic+json": { 456 | "type": "string" 457 | }, 458 | "text/plain": [ 459 | "'e'" 460 | ] 461 | }, 462 | "execution_count": 49, 463 | "metadata": { 464 | "tags": [] 465 | }, 466 | "output_type": "execute_result" 467 | } 468 | ], 469 | "source": [ 470 | "string1[3]" 471 | ] 472 | }, 473 | { 474 | "cell_type": "markdown", 475 | "metadata": { 476 | "id": "oA_UD0JV7oPw" 477 | }, 478 | "source": [ 479 | "and similarly for slices" 480 | ] 481 | }, 482 | { 483 | "cell_type": "code", 484 | "execution_count": null, 485 | "metadata": { 486 | "colab": { 487 | "base_uri": "https://localhost:8080/", 488 | "height": 35 489 | }, 490 | "id": "dcZFcLqQ7qCe", 491 | "outputId": "aba6c437-ade3-49da-9e6a-9383eab01fa9" 492 | }, 493 | "outputs": [ 494 | { 495 | "data": { 496 | "application/vnd.google.colaboratory.intrinsic+json": { 497 | "type": "string" 498 | }, 499 | "text/plain": [ 500 | "'text'" 501 | ] 502 | }, 503 | "execution_count": 53, 504 | "metadata": { 505 | "tags": [] 506 | }, 507 | "output_type": "execute_result" 508 | } 509 | ], 510 | "source": [ 511 | "string1[5:]" 512 | ] 513 | }, 514 | { 515 | "cell_type": "markdown", 516 | "metadata": { 517 | "id": "hOQ_CIiu76YG" 518 | }, 519 | "source": [ 520 | "String concatenation is performed using the `+` operator" 521 | ] 522 | }, 523 | { 524 | "cell_type": "code", 525 | "execution_count": null, 526 | "metadata": { 527 | "colab": { 528 | "base_uri": "https://localhost:8080/", 529 | "height": 35 530 | }, 531 | "id": "mxqNMKCY79_W", 532 | "outputId": "e5695c9e-0703-49b3-9608-b57ca8375ba9" 533 | }, 534 | "outputs": [ 535 | { 536 | "data": { 537 | "application/vnd.google.colaboratory.intrinsic+json": { 538 | "type": "string" 539 | }, 540 | "text/plain": [ 541 | "'some text some other text'" 542 | ] 543 | }, 544 | "execution_count": 55, 545 | "metadata": { 546 | "tags": [] 547 | }, 548 | "output_type": "execute_result" 549 | } 550 | ], 551 | "source": [ 552 | "string1 + \" \" + string2" 553 | ] 554 | }, 555 | { 556 | "cell_type": "markdown", 557 | "metadata": { 558 | "id": "7Lox2GZCMdIB" 559 | }, 560 | "source": [ 561 | "## Conditionals" 562 | ] 563 | }, 564 | { 565 | "cell_type": "markdown", 566 | "metadata": { 567 | "id": "-gXEAWFZfDTT" 568 | }, 569 | "source": [ 570 | "As their name indicates, conditionals are a way to execute code depending on whether a condition is True or False. As in other languages, Python supports `if` and `else` but `else if` is contracted into `elif`, as the example below demonstrates. " 571 | ] 572 | }, 573 | { 574 | "cell_type": "code", 575 | "execution_count": null, 576 | "metadata": { 577 | "colab": { 578 | "base_uri": "https://localhost:8080/", 579 | "height": 34 580 | }, 581 | "id": "xC_DMZjofoYZ", 582 | "outputId": "e86016aa-0ebd-4e0f-e559-326f4b2ce644" 583 | }, 584 | "outputs": [ 585 | { 586 | "name": "stdout", 587 | "output_type": "stream", 588 | "text": [ 589 | "positive\n" 590 | ] 591 | } 592 | ], 593 | "source": [ 594 | "my_variable = 5\n", 595 | "if my_variable < 0:\n", 596 | " print(\"negative\")\n", 597 | "elif my_variable == 0:\n", 598 | " print(\"null\")\n", 599 | "else: # my_variable > 0\n", 600 | " print(\"positive\")" 601 | ] 602 | }, 603 | { 604 | "cell_type": "markdown", 605 | "metadata": { 606 | "id": "Ag0SUokSf9jl" 607 | }, 608 | "source": [ 609 | "Here `<` and `>` are the strict `less` and `greater than` operators, while `==` is the equality operator (not to be confused with `=`, the variable assignment operator). The operators `<=` and `>=` can be used for less (resp. greater) than or equal comparisons." 610 | ] 611 | }, 612 | { 613 | "cell_type": "markdown", 614 | "metadata": { 615 | "id": "qTkQ2F_jy8wz" 616 | }, 617 | "source": [ 618 | "Contrary to other languages, blocks of code are delimited using indentation. Here, we use 2-space indentation but many programmers also use 4-space indentation. Any one is fine as long as you are consistent throughout your code." 619 | ] 620 | }, 621 | { 622 | "cell_type": "markdown", 623 | "metadata": { 624 | "id": "clWaFCzBMfkv" 625 | }, 626 | "source": [ 627 | "## Loops" 628 | ] 629 | }, 630 | { 631 | "cell_type": "markdown", 632 | "metadata": { 633 | "id": "_A5doqhTivWe" 634 | }, 635 | "source": [ 636 | "Loops are a way to execute a block of code multiple times. There are two main types of loops: while loops and for loops." 637 | ] 638 | }, 639 | { 640 | "cell_type": "markdown", 641 | "metadata": { 642 | "id": "YN8lwTxQkGEa" 643 | }, 644 | "source": [ 645 | "While loop" 646 | ] 647 | }, 648 | { 649 | "cell_type": "code", 650 | "execution_count": null, 651 | "metadata": { 652 | "colab": { 653 | "base_uri": "https://localhost:8080/", 654 | "height": 85 655 | }, 656 | "id": "7-QXGqgOjsr_", 657 | "outputId": "4a9bdffc-46ba-47ba-e60b-3ea01dcd2d65" 658 | }, 659 | "outputs": [ 660 | { 661 | "name": "stdout", 662 | "output_type": "stream", 663 | "text": [ 664 | "1\n", 665 | "2\n", 666 | "3\n", 667 | "4\n" 668 | ] 669 | } 670 | ], 671 | "source": [ 672 | "i = 0\n", 673 | "while i < len(my_list):\n", 674 | " print(my_list[i])\n", 675 | " i += 1 # equivalent to i = i + 1" 676 | ] 677 | }, 678 | { 679 | "cell_type": "markdown", 680 | "metadata": { 681 | "id": "8mEI_ocfkSvZ" 682 | }, 683 | "source": [ 684 | "For loop" 685 | ] 686 | }, 687 | { 688 | "cell_type": "code", 689 | "execution_count": null, 690 | "metadata": { 691 | "colab": { 692 | "base_uri": "https://localhost:8080/", 693 | "height": 85 694 | }, 695 | "id": "2QObx5mckMcI", 696 | "outputId": "32c31a79-ef89-4e80-9e76-47540f839cb6" 697 | }, 698 | "outputs": [ 699 | { 700 | "name": "stdout", 701 | "output_type": "stream", 702 | "text": [ 703 | "1\n", 704 | "2\n", 705 | "3\n", 706 | "4\n" 707 | ] 708 | } 709 | ], 710 | "source": [ 711 | "for i in range(len(my_list)):\n", 712 | " print(my_list[i])" 713 | ] 714 | }, 715 | { 716 | "cell_type": "markdown", 717 | "metadata": { 718 | "id": "XO6qqppikZvm" 719 | }, 720 | "source": [ 721 | "If the goal is simply to iterate over a list, we can do so directly as follows" 722 | ] 723 | }, 724 | { 725 | "cell_type": "code", 726 | "execution_count": null, 727 | "metadata": { 728 | "colab": { 729 | "base_uri": "https://localhost:8080/", 730 | "height": 85 731 | }, 732 | "id": "PjFKzN6zkeJ7", 733 | "outputId": "41f3a553-b629-4e52-ad98-7bbe55e0cced" 734 | }, 735 | "outputs": [ 736 | { 737 | "name": "stdout", 738 | "output_type": "stream", 739 | "text": [ 740 | "1\n", 741 | "2\n", 742 | "3\n", 743 | "4\n" 744 | ] 745 | } 746 | ], 747 | "source": [ 748 | "for element in my_list:\n", 749 | " print(element)" 750 | ] 751 | }, 752 | { 753 | "cell_type": "markdown", 754 | "metadata": { 755 | "id": "Cck4zwYrex02" 756 | }, 757 | "source": [ 758 | "## Functions" 759 | ] 760 | }, 761 | { 762 | "cell_type": "markdown", 763 | "metadata": { 764 | "id": "n1PbIf_ohxFO" 765 | }, 766 | "source": [ 767 | "To improve code readability, it is common to separate the code into different blocks, responsible for performing precise actions: functions. A function takes some inputs and process them to return some outputs." 768 | ] 769 | }, 770 | { 771 | "cell_type": "code", 772 | "execution_count": null, 773 | "metadata": { 774 | "colab": { 775 | "base_uri": "https://localhost:8080/", 776 | "height": 34 777 | }, 778 | "id": "cImA09gOhRmx", 779 | "outputId": "85834282-56d6-4c17-f188-433f46c50d21" 780 | }, 781 | "outputs": [ 782 | { 783 | "data": { 784 | "text/plain": [ 785 | "36" 786 | ] 787 | }, 788 | "execution_count": 17, 789 | "metadata": { 790 | "tags": [] 791 | }, 792 | "output_type": "execute_result" 793 | } 794 | ], 795 | "source": [ 796 | "def square(x):\n", 797 | " return x ** 2\n", 798 | "\n", 799 | "def multiply(a, b):\n", 800 | " return a * b\n", 801 | "\n", 802 | "# Functions can be composed.\n", 803 | "square(multiply(3, 2))" 804 | ] 805 | }, 806 | { 807 | "cell_type": "markdown", 808 | "metadata": { 809 | "id": "75-5SOk9iYSt" 810 | }, 811 | "source": [ 812 | "To improve code readability, it is sometimes useful to explicitly name the arguments" 813 | ] 814 | }, 815 | { 816 | "cell_type": "code", 817 | "execution_count": null, 818 | "metadata": { 819 | "colab": { 820 | "base_uri": "https://localhost:8080/", 821 | "height": 34 822 | }, 823 | "id": "wkIUuZHhidI0", 824 | "outputId": "acb68380-db78-491c-ce27-8a4664f78ce5" 825 | }, 826 | "outputs": [ 827 | { 828 | "data": { 829 | "text/plain": [ 830 | "36" 831 | ] 832 | }, 833 | "execution_count": 18, 834 | "metadata": { 835 | "tags": [] 836 | }, 837 | "output_type": "execute_result" 838 | } 839 | ], 840 | "source": [ 841 | "square(multiply(a=3, b=2))" 842 | ] 843 | }, 844 | { 845 | "cell_type": "markdown", 846 | "metadata": { 847 | "id": "LkpwbQEVMys2" 848 | }, 849 | "source": [ 850 | "## Exercises" 851 | ] 852 | }, 853 | { 854 | "cell_type": "markdown", 855 | "metadata": { 856 | "id": "ASpVhol9ZXI0" 857 | }, 858 | "source": [ 859 | "**Exercise 1.** Using a conditional, write the [relu](https://en.wikipedia.org/wiki/Rectifier_(neural_networks)) function defined as follows\n", 860 | "\n", 861 | "$\\text{relu}(x) = \\left\\{\n", 862 | " \\begin{array}{rl}\n", 863 | " x, & \\text{if } x \\ge 0 \\\\\n", 864 | " 0, & \\text{otherwise }.\n", 865 | " \\end{array}\\right.$" 866 | ] 867 | }, 868 | { 869 | "cell_type": "code", 870 | "execution_count": null, 871 | "metadata": { 872 | "id": "jlgyu65SaUvr" 873 | }, 874 | "outputs": [], 875 | "source": [ 876 | "def relu(x):\n", 877 | " # Write your function here\n", 878 | " return\n", 879 | "\n", 880 | "relu(-3)" 881 | ] 882 | }, 883 | { 884 | "cell_type": "markdown", 885 | "metadata": { 886 | "id": "Y3so0ceoakIw" 887 | }, 888 | "source": [ 889 | "**Exercise 2.** Using a foor loop, write a function that computes the [Euclidean norm](https://en.wikipedia.org/wiki/Norm_(mathematics)#Euclidean_norm) of a vector, represented as a list." 890 | ] 891 | }, 892 | { 893 | "cell_type": "code", 894 | "execution_count": null, 895 | "metadata": { 896 | "colab": { 897 | "base_uri": "https://localhost:8080/", 898 | "height": 34 899 | }, 900 | "id": "-IH-BD41bI1u", 901 | "outputId": "f45bf668-d55b-494d-ecd7-2f421cbacf15" 902 | }, 903 | "outputs": [ 904 | { 905 | "data": { 906 | "text/plain": [ 907 | "5.729746940310715" 908 | ] 909 | }, 910 | "execution_count": 13, 911 | "metadata": { 912 | "tags": [] 913 | }, 914 | "output_type": "execute_result" 915 | } 916 | ], 917 | "source": [ 918 | "def euclidean_norm(vector):\n", 919 | " # Write your function here\n", 920 | " return\n", 921 | "\n", 922 | "import numpy as np\n", 923 | "my_vector = [0.5, -1.2, 3.3, 4.5]\n", 924 | "# The result should be roughly 5.729746940310715\n", 925 | "euclidean_norm(my_vector)" 926 | ] 927 | }, 928 | { 929 | "cell_type": "markdown", 930 | "metadata": { 931 | "id": "SEXIh_e9cW3S" 932 | }, 933 | "source": [ 934 | "**Exercise 3.** Using a for loop and a conditional, write a function that returns the maximum value in a vector." 935 | ] 936 | }, 937 | { 938 | "cell_type": "code", 939 | "execution_count": null, 940 | "metadata": { 941 | "id": "zd9ntMq0cb2e" 942 | }, 943 | "outputs": [], 944 | "source": [ 945 | "def vector_maximum(vector):\n", 946 | " # Write your function here\n", 947 | " return" 948 | ] 949 | }, 950 | { 951 | "cell_type": "markdown", 952 | "metadata": { 953 | "id": "qPAZA4OMc6sT" 954 | }, 955 | "source": [ 956 | "**Bonus exercise.** if time permits, write a function that sorts a list in ascending order (from smaller to bigger) using the [bubble sort](https://en.wikipedia.org/wiki/Bubble_sort) algorithm." 957 | ] 958 | }, 959 | { 960 | "cell_type": "code", 961 | "execution_count": null, 962 | "metadata": { 963 | "id": "sBokdJO4dGyf" 964 | }, 965 | "outputs": [], 966 | "source": [ 967 | "def bubble_sort(my_list):\n", 968 | " # Write your function here\n", 969 | " return\n", 970 | "\n", 971 | "my_list = [1, -3, 3, 2]\n", 972 | "# Should return [-3, 1, 2, 3]\n", 973 | "bubble_sort(my_list)" 974 | ] 975 | }, 976 | { 977 | "cell_type": "markdown", 978 | "metadata": { 979 | "id": "jDxjvtEEM1vg" 980 | }, 981 | "source": [ 982 | "## Going further" 983 | ] 984 | }, 985 | { 986 | "cell_type": "markdown", 987 | "metadata": { 988 | "id": "wRkmvzf-PdEp" 989 | }, 990 | "source": [ 991 | "Clearly, it is impossible to cover all the language features in this short introduction. To go further, we recommend the following resources:" 992 | ] 993 | }, 994 | { 995 | "cell_type": "markdown", 996 | "metadata": { 997 | "id": "6X4WJo3iM6m9" 998 | }, 999 | "source": [ 1000 | "# NumPy" 1001 | ] 1002 | }, 1003 | { 1004 | "cell_type": "markdown", 1005 | "metadata": { 1006 | "id": "_H3bNbLloXCY" 1007 | }, 1008 | "source": [ 1009 | "NumPy is a popular library for storing arrays of numbers and performing computations on them. Not only this enables to write often more succint code, this also makes the code faster, since most NumPy routines are implemented in C for speed." 1010 | ] 1011 | }, 1012 | { 1013 | "cell_type": "markdown", 1014 | "metadata": { 1015 | "id": "M7tI3XLhqwSX" 1016 | }, 1017 | "source": [ 1018 | "To use NumPy in your program, you need to import it as follows" 1019 | ] 1020 | }, 1021 | { 1022 | "cell_type": "code", 1023 | "execution_count": null, 1024 | "metadata": { 1025 | "id": "phSPPyfyq2gX" 1026 | }, 1027 | "outputs": [], 1028 | "source": [ 1029 | "import numpy as np" 1030 | ] 1031 | }, 1032 | { 1033 | "cell_type": "markdown", 1034 | "metadata": { 1035 | "id": "9secCfFLNHEE" 1036 | }, 1037 | "source": [ 1038 | "## Array creation\n", 1039 | "\n" 1040 | ] 1041 | }, 1042 | { 1043 | "cell_type": "markdown", 1044 | "metadata": { 1045 | "id": "LSS2wEnkq97n" 1046 | }, 1047 | "source": [ 1048 | "NumPy arrays can be created from Python lists" 1049 | ] 1050 | }, 1051 | { 1052 | "cell_type": "code", 1053 | "execution_count": null, 1054 | "metadata": { 1055 | "colab": { 1056 | "base_uri": "https://localhost:8080/", 1057 | "height": 34 1058 | }, 1059 | "id": "Hfeg286yrLvJ", 1060 | "outputId": "f498bafc-0373-4258-f479-e27716b193c1" 1061 | }, 1062 | "outputs": [ 1063 | { 1064 | "data": { 1065 | "text/plain": [ 1066 | "array([1, 2, 3])" 1067 | ] 1068 | }, 1069 | "execution_count": 27, 1070 | "metadata": { 1071 | "tags": [] 1072 | }, 1073 | "output_type": "execute_result" 1074 | } 1075 | ], 1076 | "source": [ 1077 | "my_array = np.array([1, 2, 3])\n", 1078 | "my_array" 1079 | ] 1080 | }, 1081 | { 1082 | "cell_type": "markdown", 1083 | "metadata": { 1084 | "id": "Sy2EvrxFriAG" 1085 | }, 1086 | "source": [ 1087 | "NumPy supports array of arbitrary dimension. For example, we can create two-dimensional arrays (e.g. to store a matrix) as follows" 1088 | ] 1089 | }, 1090 | { 1091 | "cell_type": "code", 1092 | "execution_count": null, 1093 | "metadata": { 1094 | "colab": { 1095 | "base_uri": "https://localhost:8080/", 1096 | "height": 51 1097 | }, 1098 | "id": "wM-GYVMsrzNs", 1099 | "outputId": "3d524d20-cf2c-4d3c-ba08-4552be3a46d8" 1100 | }, 1101 | "outputs": [ 1102 | { 1103 | "data": { 1104 | "text/plain": [ 1105 | "array([[1, 2, 3],\n", 1106 | " [4, 5, 6]])" 1107 | ] 1108 | }, 1109 | "execution_count": 28, 1110 | "metadata": { 1111 | "tags": [] 1112 | }, 1113 | "output_type": "execute_result" 1114 | } 1115 | ], 1116 | "source": [ 1117 | "my_2d_array = np.array([[1, 2, 3], [4, 5, 6]])\n", 1118 | "my_2d_array" 1119 | ] 1120 | }, 1121 | { 1122 | "cell_type": "markdown", 1123 | "metadata": { 1124 | "id": "-kZMzYsAsVAc" 1125 | }, 1126 | "source": [ 1127 | "We can access individual elements of a 2d-array using two indices" 1128 | ] 1129 | }, 1130 | { 1131 | "cell_type": "code", 1132 | "execution_count": null, 1133 | "metadata": { 1134 | "colab": { 1135 | "base_uri": "https://localhost:8080/", 1136 | "height": 34 1137 | }, 1138 | "id": "4q8X86BbscPd", 1139 | "outputId": "3cefe32a-690a-4744-fad9-9c3edd763cd6" 1140 | }, 1141 | "outputs": [ 1142 | { 1143 | "data": { 1144 | "text/plain": [ 1145 | "6" 1146 | ] 1147 | }, 1148 | "execution_count": 30, 1149 | "metadata": { 1150 | "tags": [] 1151 | }, 1152 | "output_type": "execute_result" 1153 | } 1154 | ], 1155 | "source": [ 1156 | "my_2d_array[1, 2]" 1157 | ] 1158 | }, 1159 | { 1160 | "cell_type": "markdown", 1161 | "metadata": { 1162 | "id": "OfVIKyxkTh0p" 1163 | }, 1164 | "source": [ 1165 | "We can also access rows" 1166 | ] 1167 | }, 1168 | { 1169 | "cell_type": "code", 1170 | "execution_count": null, 1171 | "metadata": { 1172 | "colab": { 1173 | "base_uri": "https://localhost:8080/", 1174 | "height": 34 1175 | }, 1176 | "id": "CrKnDAtyTlYe", 1177 | "outputId": "14060c28-8ee7-48f5-f0ca-bdcff12cc421" 1178 | }, 1179 | "outputs": [ 1180 | { 1181 | "data": { 1182 | "text/plain": [ 1183 | "array([4, 5, 6])" 1184 | ] 1185 | }, 1186 | "execution_count": 66, 1187 | "metadata": { 1188 | "tags": [] 1189 | }, 1190 | "output_type": "execute_result" 1191 | } 1192 | ], 1193 | "source": [ 1194 | "my_2d_array[1]" 1195 | ] 1196 | }, 1197 | { 1198 | "cell_type": "markdown", 1199 | "metadata": { 1200 | "id": "hskLBCp9ToCG" 1201 | }, 1202 | "source": [ 1203 | "and columns" 1204 | ] 1205 | }, 1206 | { 1207 | "cell_type": "code", 1208 | "execution_count": null, 1209 | "metadata": { 1210 | "colab": { 1211 | "base_uri": "https://localhost:8080/", 1212 | "height": 34 1213 | }, 1214 | "id": "MOOFsLHhTozX", 1215 | "outputId": "8802a59a-0812-40a4-f930-ab2a3302bf46" 1216 | }, 1217 | "outputs": [ 1218 | { 1219 | "data": { 1220 | "text/plain": [ 1221 | "array([3, 6])" 1222 | ] 1223 | }, 1224 | "execution_count": 67, 1225 | "metadata": { 1226 | "tags": [] 1227 | }, 1228 | "output_type": "execute_result" 1229 | } 1230 | ], 1231 | "source": [ 1232 | "my_2d_array[:, 2]" 1233 | ] 1234 | }, 1235 | { 1236 | "cell_type": "markdown", 1237 | "metadata": { 1238 | "id": "keWK_5PHr9Q2" 1239 | }, 1240 | "source": [ 1241 | "Arrays have a `shape` attribute" 1242 | ] 1243 | }, 1244 | { 1245 | "cell_type": "code", 1246 | "execution_count": null, 1247 | "metadata": { 1248 | "colab": { 1249 | "base_uri": "https://localhost:8080/", 1250 | "height": 51 1251 | }, 1252 | "id": "5QIo7l1Yr8m7", 1253 | "outputId": "357d4218-541d-4c7f-8bcf-b3f4523b1fa3" 1254 | }, 1255 | "outputs": [ 1256 | { 1257 | "name": "stdout", 1258 | "output_type": "stream", 1259 | "text": [ 1260 | "(3,)\n", 1261 | "(2, 3)\n" 1262 | ] 1263 | } 1264 | ], 1265 | "source": [ 1266 | "print(my_array.shape)\n", 1267 | "print(my_2d_array.shape)" 1268 | ] 1269 | }, 1270 | { 1271 | "cell_type": "markdown", 1272 | "metadata": { 1273 | "id": "LmX0EDWVsoDY" 1274 | }, 1275 | "source": [ 1276 | "Contrary to Python lists, NumPy arrays must have a type and all elements of the array must have the same type." 1277 | ] 1278 | }, 1279 | { 1280 | "cell_type": "code", 1281 | "execution_count": null, 1282 | "metadata": { 1283 | "colab": { 1284 | "base_uri": "https://localhost:8080/", 1285 | "height": 34 1286 | }, 1287 | "id": "FZjOowkls57o", 1288 | "outputId": "abb3edab-a903-40c8-f88a-1125fc6d4dbf" 1289 | }, 1290 | "outputs": [ 1291 | { 1292 | "data": { 1293 | "text/plain": [ 1294 | "dtype('int64')" 1295 | ] 1296 | }, 1297 | "execution_count": 31, 1298 | "metadata": { 1299 | "tags": [] 1300 | }, 1301 | "output_type": "execute_result" 1302 | } 1303 | ], 1304 | "source": [ 1305 | "my_array.dtype" 1306 | ] 1307 | }, 1308 | { 1309 | "cell_type": "markdown", 1310 | "metadata": { 1311 | "id": "i5AvLdf7tGnZ" 1312 | }, 1313 | "source": [ 1314 | "The main types are `int32` (32-bit integers), `int64` (64-bit integers), `float32` (32-bit real values) and `float64` (64-bit real values)." 1315 | ] 1316 | }, 1317 | { 1318 | "cell_type": "markdown", 1319 | "metadata": { 1320 | "id": "w8ym2qZCt9Nm" 1321 | }, 1322 | "source": [ 1323 | "The `dtype` can be specified when creating the array" 1324 | ] 1325 | }, 1326 | { 1327 | "cell_type": "code", 1328 | "execution_count": null, 1329 | "metadata": { 1330 | "colab": { 1331 | "base_uri": "https://localhost:8080/", 1332 | "height": 34 1333 | }, 1334 | "id": "gXpM_FqruCVv", 1335 | "outputId": "20d8b981-56ed-4458-d9d8-2f9fb5fb2b58" 1336 | }, 1337 | "outputs": [ 1338 | { 1339 | "data": { 1340 | "text/plain": [ 1341 | "dtype('float64')" 1342 | ] 1343 | }, 1344 | "execution_count": 32, 1345 | "metadata": { 1346 | "tags": [] 1347 | }, 1348 | "output_type": "execute_result" 1349 | } 1350 | ], 1351 | "source": [ 1352 | "my_array = np.array([1, 2, 3], dtype=np.float64)\n", 1353 | "my_array.dtype" 1354 | ] 1355 | }, 1356 | { 1357 | "cell_type": "markdown", 1358 | "metadata": { 1359 | "id": "WueaRIONuTdS" 1360 | }, 1361 | "source": [ 1362 | "We can create arrays of all zeros using" 1363 | ] 1364 | }, 1365 | { 1366 | "cell_type": "code", 1367 | "execution_count": null, 1368 | "metadata": { 1369 | "colab": { 1370 | "base_uri": "https://localhost:8080/", 1371 | "height": 51 1372 | }, 1373 | "id": "jbD8N1UauK8r", 1374 | "outputId": "4a352f81-f0e8-4bc1-a651-760436c7d213" 1375 | }, 1376 | "outputs": [ 1377 | { 1378 | "data": { 1379 | "text/plain": [ 1380 | "array([[0., 0., 0.],\n", 1381 | " [0., 0., 0.]])" 1382 | ] 1383 | }, 1384 | "execution_count": 33, 1385 | "metadata": { 1386 | "tags": [] 1387 | }, 1388 | "output_type": "execute_result" 1389 | } 1390 | ], 1391 | "source": [ 1392 | "zero_array = np.zeros((2, 3))\n", 1393 | "zero_array" 1394 | ] 1395 | }, 1396 | { 1397 | "cell_type": "markdown", 1398 | "metadata": { 1399 | "id": "vn5go6qoudo4" 1400 | }, 1401 | "source": [ 1402 | "and similarly for all ones using `ones` instead of `zeros`." 1403 | ] 1404 | }, 1405 | { 1406 | "cell_type": "markdown", 1407 | "metadata": { 1408 | "id": "1kCRlhLJuvZ6" 1409 | }, 1410 | "source": [ 1411 | "We can create a range of values using" 1412 | ] 1413 | }, 1414 | { 1415 | "cell_type": "code", 1416 | "execution_count": null, 1417 | "metadata": { 1418 | "colab": { 1419 | "base_uri": "https://localhost:8080/", 1420 | "height": 34 1421 | }, 1422 | "id": "EcQXDeEmuxpO", 1423 | "outputId": "5a6fac79-26e3-4012-d5f4-82844372dc58" 1424 | }, 1425 | "outputs": [ 1426 | { 1427 | "data": { 1428 | "text/plain": [ 1429 | "array([0, 1, 2, 3, 4])" 1430 | ] 1431 | }, 1432 | "execution_count": 34, 1433 | "metadata": { 1434 | "tags": [] 1435 | }, 1436 | "output_type": "execute_result" 1437 | } 1438 | ], 1439 | "source": [ 1440 | "np.arange(5)" 1441 | ] 1442 | }, 1443 | { 1444 | "cell_type": "markdown", 1445 | "metadata": { 1446 | "id": "ZvJECk6Iu3uF" 1447 | }, 1448 | "source": [ 1449 | "or specifying the starting point" 1450 | ] 1451 | }, 1452 | { 1453 | "cell_type": "code", 1454 | "execution_count": null, 1455 | "metadata": { 1456 | "colab": { 1457 | "base_uri": "https://localhost:8080/", 1458 | "height": 34 1459 | }, 1460 | "id": "Pk3UzL3du_f8", 1461 | "outputId": "1fd3f3fa-63ba-4a26-9274-011574bebbd2" 1462 | }, 1463 | "outputs": [ 1464 | { 1465 | "data": { 1466 | "text/plain": [ 1467 | "array([3, 4])" 1468 | ] 1469 | }, 1470 | "execution_count": 35, 1471 | "metadata": { 1472 | "tags": [] 1473 | }, 1474 | "output_type": "execute_result" 1475 | } 1476 | ], 1477 | "source": [ 1478 | "np.arange(3, 5)" 1479 | ] 1480 | }, 1481 | { 1482 | "cell_type": "markdown", 1483 | "metadata": { 1484 | "id": "f1JtqFSivJKG" 1485 | }, 1486 | "source": [ 1487 | "Another useful routine is `linspace` for creating linearly spaced values in an interval. For instance, to create 10 values in `[0, 1]`, we can use" 1488 | ] 1489 | }, 1490 | { 1491 | "cell_type": "code", 1492 | "execution_count": null, 1493 | "metadata": { 1494 | "colab": { 1495 | "base_uri": "https://localhost:8080/", 1496 | "height": 51 1497 | }, 1498 | "id": "udHHjGAHvOQM", 1499 | "outputId": "473cec27-ac56-4dc9-984a-c1e340255a51" 1500 | }, 1501 | "outputs": [ 1502 | { 1503 | "data": { 1504 | "text/plain": [ 1505 | "array([0. , 0.11111111, 0.22222222, 0.33333333, 0.44444444,\n", 1506 | " 0.55555556, 0.66666667, 0.77777778, 0.88888889, 1. ])" 1507 | ] 1508 | }, 1509 | "execution_count": 36, 1510 | "metadata": { 1511 | "tags": [] 1512 | }, 1513 | "output_type": "execute_result" 1514 | } 1515 | ], 1516 | "source": [ 1517 | "np.linspace(0, 1, 10)" 1518 | ] 1519 | }, 1520 | { 1521 | "cell_type": "markdown", 1522 | "metadata": { 1523 | "id": "WbcxAKobvgUT" 1524 | }, 1525 | "source": [ 1526 | "Another important operation is `reshape`, for changing the shape of an array" 1527 | ] 1528 | }, 1529 | { 1530 | "cell_type": "code", 1531 | "execution_count": null, 1532 | "metadata": { 1533 | "colab": { 1534 | "base_uri": "https://localhost:8080/", 1535 | "height": 68 1536 | }, 1537 | "id": "4FPzTuDlvlLO", 1538 | "outputId": "338648ec-11e3-436f-d0e4-6745f9cb30d3" 1539 | }, 1540 | "outputs": [ 1541 | { 1542 | "data": { 1543 | "text/plain": [ 1544 | "array([[1, 2],\n", 1545 | " [3, 4],\n", 1546 | " [5, 6]])" 1547 | ] 1548 | }, 1549 | "execution_count": 37, 1550 | "metadata": { 1551 | "tags": [] 1552 | }, 1553 | "output_type": "execute_result" 1554 | } 1555 | ], 1556 | "source": [ 1557 | "my_array = np.array([1, 2, 3, 4, 5, 6])\n", 1558 | "my_array.reshape(3, 2)" 1559 | ] 1560 | }, 1561 | { 1562 | "cell_type": "markdown", 1563 | "metadata": { 1564 | "id": "G-QR80_g3N9Y" 1565 | }, 1566 | "source": [ 1567 | "Play with these operations and make sure you understand them well." 1568 | ] 1569 | }, 1570 | { 1571 | "cell_type": "markdown", 1572 | "metadata": { 1573 | "id": "f9B0iCBlmfeY" 1574 | }, 1575 | "source": [ 1576 | "## Basic operations" 1577 | ] 1578 | }, 1579 | { 1580 | "cell_type": "markdown", 1581 | "metadata": { 1582 | "id": "elQGgkqDxKLV" 1583 | }, 1584 | "source": [ 1585 | "In NumPy, we express computations directly over arrays. This makes the code much more succint." 1586 | ] 1587 | }, 1588 | { 1589 | "cell_type": "markdown", 1590 | "metadata": { 1591 | "id": "hkCU1T8ixghX" 1592 | }, 1593 | "source": [ 1594 | "Arithmetic operations can be performed directly over arrays. For instance, assuming two arrays have a compatible shape, we can add them as follows" 1595 | ] 1596 | }, 1597 | { 1598 | "cell_type": "code", 1599 | "execution_count": null, 1600 | "metadata": { 1601 | "colab": { 1602 | "base_uri": "https://localhost:8080/", 1603 | "height": 34 1604 | }, 1605 | "id": "4AoiRq42x5mI", 1606 | "outputId": "d9706493-95f8-43d5-af90-21a53c13cac5" 1607 | }, 1608 | "outputs": [ 1609 | { 1610 | "data": { 1611 | "text/plain": [ 1612 | "array([5, 7, 9])" 1613 | ] 1614 | }, 1615 | "execution_count": 38, 1616 | "metadata": { 1617 | "tags": [] 1618 | }, 1619 | "output_type": "execute_result" 1620 | } 1621 | ], 1622 | "source": [ 1623 | "array_a = np.array([1, 2, 3])\n", 1624 | "array_b = np.array([4, 5, 6])\n", 1625 | "array_a + array_b" 1626 | ] 1627 | }, 1628 | { 1629 | "cell_type": "markdown", 1630 | "metadata": { 1631 | "id": "SyPqME2EyD4x" 1632 | }, 1633 | "source": [ 1634 | "Compare this with the equivalent computation using a for loop" 1635 | ] 1636 | }, 1637 | { 1638 | "cell_type": "code", 1639 | "execution_count": null, 1640 | "metadata": { 1641 | "colab": { 1642 | "base_uri": "https://localhost:8080/", 1643 | "height": 34 1644 | }, 1645 | "id": "HxRFA_U2yfI-", 1646 | "outputId": "cbd77fed-8b67-4119-aeea-7a71d92b63b6" 1647 | }, 1648 | "outputs": [ 1649 | { 1650 | "data": { 1651 | "text/plain": [ 1652 | "array([5, 7, 9])" 1653 | ] 1654 | }, 1655 | "execution_count": 65, 1656 | "metadata": { 1657 | "tags": [] 1658 | }, 1659 | "output_type": "execute_result" 1660 | } 1661 | ], 1662 | "source": [ 1663 | "array_out = np.zeros_like(array_a)\n", 1664 | "for i in range(len(array_a)):\n", 1665 | " array_out[i] = array_a[i] + array_b[i]\n", 1666 | "array_out" 1667 | ] 1668 | }, 1669 | { 1670 | "cell_type": "markdown", 1671 | "metadata": { 1672 | "id": "i2a-apX-zlPN" 1673 | }, 1674 | "source": [ 1675 | "Not only this code is more verbose, it will also run much more slowly." 1676 | ] 1677 | }, 1678 | { 1679 | "cell_type": "markdown", 1680 | "metadata": { 1681 | "id": "Qdn8MwpR0wX_" 1682 | }, 1683 | "source": [ 1684 | "In NumPy, functions that operates on arrays in an element-wise fashion are called [universal functions](https://numpy.org/doc/stable/reference/ufuncs.html). For instance, this is the case of `np.sin`" 1685 | ] 1686 | }, 1687 | { 1688 | "cell_type": "code", 1689 | "execution_count": null, 1690 | "metadata": { 1691 | "colab": { 1692 | "base_uri": "https://localhost:8080/", 1693 | "height": 34 1694 | }, 1695 | "id": "JoanjiMu1BH5", 1696 | "outputId": "e6b8be44-7e66-4a3f-eb57-c767c7f8b2f3" 1697 | }, 1698 | "outputs": [ 1699 | { 1700 | "data": { 1701 | "text/plain": [ 1702 | "array([0.84147098, 0.90929743, 0.14112001])" 1703 | ] 1704 | }, 1705 | "execution_count": 41, 1706 | "metadata": { 1707 | "tags": [] 1708 | }, 1709 | "output_type": "execute_result" 1710 | } 1711 | ], 1712 | "source": [ 1713 | "np.sin(array_a)" 1714 | ] 1715 | }, 1716 | { 1717 | "cell_type": "markdown", 1718 | "metadata": { 1719 | "id": "jHljrPXg5h8W" 1720 | }, 1721 | "source": [ 1722 | "Vector inner product can be performed using `np.dot`" 1723 | ] 1724 | }, 1725 | { 1726 | "cell_type": "code", 1727 | "execution_count": null, 1728 | "metadata": { 1729 | "colab": { 1730 | "base_uri": "https://localhost:8080/", 1731 | "height": 34 1732 | }, 1733 | "id": "TphR8oIx5ob9", 1734 | "outputId": "a84a8966-6b99-4a48-b422-caea4dd0ffc6" 1735 | }, 1736 | "outputs": [ 1737 | { 1738 | "data": { 1739 | "text/plain": [ 1740 | "32" 1741 | ] 1742 | }, 1743 | "execution_count": 44, 1744 | "metadata": { 1745 | "tags": [] 1746 | }, 1747 | "output_type": "execute_result" 1748 | } 1749 | ], 1750 | "source": [ 1751 | "np.dot(array_a, array_b)" 1752 | ] 1753 | }, 1754 | { 1755 | "cell_type": "markdown", 1756 | "metadata": { 1757 | "id": "lHInOiSW50OR" 1758 | }, 1759 | "source": [ 1760 | "When the two arguments to `np.dot` are both 2d arrays, `np.dot` becomes matrix multiplication" 1761 | ] 1762 | }, 1763 | { 1764 | "cell_type": "code", 1765 | "execution_count": null, 1766 | "metadata": { 1767 | "colab": { 1768 | "base_uri": "https://localhost:8080/", 1769 | "height": 102 1770 | }, 1771 | "id": "QRbpbhPP6Up0", 1772 | "outputId": "d020a4d4-2532-495f-fd28-766fc92b3318" 1773 | }, 1774 | "outputs": [ 1775 | { 1776 | "data": { 1777 | "text/plain": [ 1778 | "array([[-0.36045702, -0.81071381, -0.19270751, 1.68942764],\n", 1779 | " [-1.37444349, -3.05245084, -0.52466652, -0.02343348],\n", 1780 | " [-1.43277431, -2.95828896, -0.4035378 , -0.50852563],\n", 1781 | " [-0.8569399 , -0.99003545, 0.17051909, 1.02933425],\n", 1782 | " [-0.47198448, -1.52564526, -0.41890404, -1.29330023]])" 1783 | ] 1784 | }, 1785 | "execution_count": 45, 1786 | "metadata": { 1787 | "tags": [] 1788 | }, 1789 | "output_type": "execute_result" 1790 | } 1791 | ], 1792 | "source": [ 1793 | "array_A = np.random.rand(5, 3)\n", 1794 | "array_B = np.random.randn(3, 4)\n", 1795 | "np.dot(array_A, array_B)" 1796 | ] 1797 | }, 1798 | { 1799 | "cell_type": "markdown", 1800 | "metadata": { 1801 | "id": "odVawD9m6gwv" 1802 | }, 1803 | "source": [ 1804 | "Matrix transpose can be done using `.transpose()` or `.T` for short" 1805 | ] 1806 | }, 1807 | { 1808 | "cell_type": "code", 1809 | "execution_count": null, 1810 | "metadata": { 1811 | "colab": { 1812 | "base_uri": "https://localhost:8080/", 1813 | "height": 68 1814 | }, 1815 | "id": "gvPe_JAO6mvF", 1816 | "outputId": "4952000d-c255-4cd0-8b12-51bcb59ba53b" 1817 | }, 1818 | "outputs": [ 1819 | { 1820 | "data": { 1821 | "text/plain": [ 1822 | "array([[0.83246658, 0.86545167, 0.62386601, 0.473339 , 0.06991272],\n", 1823 | " [0.02185012, 0.93435538, 0.93170156, 0.0036374 , 0.7230155 ],\n", 1824 | " [0.08128956, 0.83778882, 0.96709345, 0.66291745, 0.2734715 ]])" 1825 | ] 1826 | }, 1827 | "execution_count": 46, 1828 | "metadata": { 1829 | "tags": [] 1830 | }, 1831 | "output_type": "execute_result" 1832 | } 1833 | ], 1834 | "source": [ 1835 | "array_A.T" 1836 | ] 1837 | }, 1838 | { 1839 | "cell_type": "markdown", 1840 | "metadata": { 1841 | "id": "JlWt3oFnE_E-" 1842 | }, 1843 | "source": [ 1844 | "## Slicing and masking" 1845 | ] 1846 | }, 1847 | { 1848 | "cell_type": "markdown", 1849 | "metadata": { 1850 | "id": "e4aKKe7bFA65" 1851 | }, 1852 | "source": [ 1853 | "Like Python lists, NumPy arrays support slicing" 1854 | ] 1855 | }, 1856 | { 1857 | "cell_type": "code", 1858 | "execution_count": null, 1859 | "metadata": { 1860 | "colab": { 1861 | "base_uri": "https://localhost:8080/", 1862 | "height": 34 1863 | }, 1864 | "id": "0kPhv2xcF1TP", 1865 | "outputId": "a7315cac-0495-44da-e497-63aa677b8d47" 1866 | }, 1867 | "outputs": [ 1868 | { 1869 | "data": { 1870 | "text/plain": [ 1871 | "array([5, 6, 7, 8, 9])" 1872 | ] 1873 | }, 1874 | "execution_count": 61, 1875 | "metadata": { 1876 | "tags": [] 1877 | }, 1878 | "output_type": "execute_result" 1879 | } 1880 | ], 1881 | "source": [ 1882 | "np.arange(10)[5:]" 1883 | ] 1884 | }, 1885 | { 1886 | "cell_type": "markdown", 1887 | "metadata": { 1888 | "id": "ITu2Wy4-GB2G" 1889 | }, 1890 | "source": [ 1891 | "We can also select only certain elements from the array" 1892 | ] 1893 | }, 1894 | { 1895 | "cell_type": "code", 1896 | "execution_count": null, 1897 | "metadata": { 1898 | "colab": { 1899 | "base_uri": "https://localhost:8080/", 1900 | "height": 34 1901 | }, 1902 | "id": "8tlZzTB6GEyw", 1903 | "outputId": "a2918cd3-f33b-48de-cd18-a3a8b1fb2fab" 1904 | }, 1905 | "outputs": [ 1906 | { 1907 | "data": { 1908 | "text/plain": [ 1909 | "array([5, 6, 7, 8, 9])" 1910 | ] 1911 | }, 1912 | "execution_count": 62, 1913 | "metadata": { 1914 | "tags": [] 1915 | }, 1916 | "output_type": "execute_result" 1917 | } 1918 | ], 1919 | "source": [ 1920 | "x = np.arange(10)\n", 1921 | "mask = x >= 5\n", 1922 | "x[mask]" 1923 | ] 1924 | }, 1925 | { 1926 | "cell_type": "markdown", 1927 | "metadata": { 1928 | "id": "NlGForCimjBL" 1929 | }, 1930 | "source": [ 1931 | "## Exercises" 1932 | ] 1933 | }, 1934 | { 1935 | "cell_type": "markdown", 1936 | "metadata": { 1937 | "id": "Ur1UlSFPTu6O" 1938 | }, 1939 | "source": [ 1940 | "**Exercise 1.** Create a 3d array of shape (2, 2, 2), containing 8 values. Access individual elements and slices." 1941 | ] 1942 | }, 1943 | { 1944 | "cell_type": "code", 1945 | "execution_count": null, 1946 | "metadata": { 1947 | "id": "v1ed4-vLUWXQ" 1948 | }, 1949 | "outputs": [], 1950 | "source": [] 1951 | }, 1952 | { 1953 | "cell_type": "markdown", 1954 | "metadata": { 1955 | "id": "s_ksfCDJzyxI" 1956 | }, 1957 | "source": [ 1958 | "**Exercise 2.** Rewrite the relu function (see Python section) using [np.maximum](https://numpy.org/doc/stable/reference/generated/numpy.maximum.html). Check that it works on both a single value and on an array of values." 1959 | ] 1960 | }, 1961 | { 1962 | "cell_type": "code", 1963 | "execution_count": null, 1964 | "metadata": { 1965 | "id": "QtSTxH5Dz6f8" 1966 | }, 1967 | "outputs": [], 1968 | "source": [ 1969 | "def relu_numpy(x):\n", 1970 | " return\n", 1971 | "\n", 1972 | "relu_numpy(np.array([1, -3, 2.5]))" 1973 | ] 1974 | }, 1975 | { 1976 | "cell_type": "markdown", 1977 | "metadata": { 1978 | "id": "wggUjpyRz7fb" 1979 | }, 1980 | "source": [ 1981 | "**Exercise 3.** Rewrite the Euclidean norm of a vector (1d array) using NumPy (without for loop)" 1982 | ] 1983 | }, 1984 | { 1985 | "cell_type": "code", 1986 | "execution_count": null, 1987 | "metadata": { 1988 | "id": "p5BLcHOD0Bhy" 1989 | }, 1990 | "outputs": [], 1991 | "source": [ 1992 | "def euclidean_norm_numpy(x):\n", 1993 | " return\n", 1994 | "\n", 1995 | "my_vector = np.array([0.5, -1.2, 3.3, 4.5])\n", 1996 | "euclidean_norm_numpy(my_vector)" 1997 | ] 1998 | }, 1999 | { 2000 | "cell_type": "markdown", 2001 | "metadata": { 2002 | "id": "01IteVJ60Il2" 2003 | }, 2004 | "source": [ 2005 | "**Exercise 4.** Write a function that computes the Euclidean norms of a matrix (2d array) in a row-wise fashion. Hint: use the `axis` argument of [np.sum](https://numpy.org/doc/stable/reference/generated/numpy.sum.html)." 2006 | ] 2007 | }, 2008 | { 2009 | "cell_type": "code", 2010 | "execution_count": null, 2011 | "metadata": { 2012 | "id": "at5lWRNM0SVG" 2013 | }, 2014 | "outputs": [], 2015 | "source": [ 2016 | "def euclidean_norm_2d(X):\n", 2017 | " return\n", 2018 | "\n", 2019 | "my_matrix = np.array([[0.5, -1.2, 4.5],\n", 2020 | " [-3.2, 1.9, 2.7]])\n", 2021 | "# Should return an array of size 2.\n", 2022 | "euclidean_norm_2d(my_matrix)" 2023 | ] 2024 | }, 2025 | { 2026 | "cell_type": "markdown", 2027 | "metadata": { 2028 | "id": "yd1ZoByo436x" 2029 | }, 2030 | "source": [ 2031 | "**Exercise 5.** Compute the mean value of the features in the [iris dataset](https://scikit-learn.org/stable/modules/generated/sklearn.datasets.load_iris.html). Hint: use the `axis` argument on [np.mean](https://numpy.org/doc/stable/reference/generated/numpy.mean.html)." 2032 | ] 2033 | }, 2034 | { 2035 | "cell_type": "code", 2036 | "execution_count": null, 2037 | "metadata": { 2038 | "colab": { 2039 | "base_uri": "https://localhost:8080/", 2040 | "height": 34 2041 | }, 2042 | "id": "fYFVobkP5JK6", 2043 | "outputId": "91504ff7-ad59-4eb7-f940-cb2e068e1b6f" 2044 | }, 2045 | "outputs": [ 2046 | { 2047 | "data": { 2048 | "text/plain": [ 2049 | "(150, 4)" 2050 | ] 2051 | }, 2052 | "execution_count": 43, 2053 | "metadata": { 2054 | "tags": [] 2055 | }, 2056 | "output_type": "execute_result" 2057 | } 2058 | ], 2059 | "source": [ 2060 | "from sklearn.datasets import load_iris\n", 2061 | "X, y = load_iris(return_X_y=True)\n", 2062 | "\n", 2063 | "# Result should be an array of size 4." 2064 | ] 2065 | }, 2066 | { 2067 | "cell_type": "markdown", 2068 | "metadata": { 2069 | "id": "1FDs9zX6mpoX" 2070 | }, 2071 | "source": [ 2072 | "## Going further" 2073 | ] 2074 | }, 2075 | { 2076 | "cell_type": "markdown", 2077 | "metadata": { 2078 | "id": "hFP61Iztmr9Q" 2079 | }, 2080 | "source": [ 2081 | "* NumPy [reference](https://numpy.org/doc/stable/reference/)\n", 2082 | "* SciPy [lectures](https://scipy-lectures.org/)\n", 2083 | "\n", 2084 | "\n" 2085 | ] 2086 | }, 2087 | { 2088 | "cell_type": "markdown", 2089 | "metadata": { 2090 | "id": "7Jt6T3kJ8I2T" 2091 | }, 2092 | "source": [ 2093 | "# Matplotlib" 2094 | ] 2095 | }, 2096 | { 2097 | "cell_type": "markdown", 2098 | "metadata": { 2099 | "id": "kQX8TiEOALkQ" 2100 | }, 2101 | "source": [ 2102 | "## Basic plots" 2103 | ] 2104 | }, 2105 | { 2106 | "cell_type": "markdown", 2107 | "metadata": { 2108 | "id": "REYwc9Va8UTg" 2109 | }, 2110 | "source": [ 2111 | "Matplotlib is a plotting library for Python." 2112 | ] 2113 | }, 2114 | { 2115 | "cell_type": "markdown", 2116 | "metadata": { 2117 | "id": "Eom7t-m6-Uzb" 2118 | }, 2119 | "source": [ 2120 | "We start with a rudimentary plotting example." 2121 | ] 2122 | }, 2123 | { 2124 | "cell_type": "code", 2125 | "execution_count": null, 2126 | "metadata": { 2127 | "colab": { 2128 | "base_uri": "https://localhost:8080/", 2129 | "height": 295 2130 | }, 2131 | "id": "g21e5Ncm927z", 2132 | "outputId": "0bffba14-376e-4274-a33a-04cc8ce6cd64" 2133 | }, 2134 | "outputs": [ 2135 | { 2136 | "data": { 2137 | "image/png": "iVBORw0KGgoAAAANSUhEUgAAAZAAAAEWCAYAAABIVsEJAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjIsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+WH4yJAAAgAElEQVR4nO3dd3hUZdrH8e+dDgQCJCFAIITeewAVRZSqqMEKdmQtW2zrquiLqy6KixV111WxrKALdgUBRUBsS5GE3gmhhRoSagKp9/vHDO4QE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ib4xpK1afHmTHmJBsPxBgHicgtQJ6qTnWPj75QRC5W1e+czmbMmdgZiDHGmDKxNhBjjDFlYgXEGGNMmVgBMcYYUyZWQIwxxpSJFRBjjDFlYgXEGGNMmVgBMcYYUyb/D+1Fv307TjxlAAAAAElFTkSuQmCC\n", 2138 | "text/plain": [ 2139 | "
" 2140 | ] 2141 | }, 2142 | "metadata": { 2143 | "needs_background": "light", 2144 | "tags": [] 2145 | }, 2146 | "output_type": "display_data" 2147 | } 2148 | ], 2149 | "source": [ 2150 | "from matplotlib import pyplot as plt\n", 2151 | "\n", 2152 | "x_values = np.linspace(-3, 3, 100)\n", 2153 | "\n", 2154 | "plt.figure()\n", 2155 | "plt.plot(x_values, np.sin(x_values), label=\"Sinusoid\")\n", 2156 | "plt.xlabel(\"x\")\n", 2157 | "plt.ylabel(\"sin(x)\")\n", 2158 | "plt.title(\"Matplotlib example\")\n", 2159 | "plt.legend(loc=\"upper left\")\n", 2160 | "plt.show()" 2161 | ] 2162 | }, 2163 | { 2164 | "cell_type": "markdown", 2165 | "metadata": { 2166 | "id": "ltvlLwXF-eAH" 2167 | }, 2168 | "source": [ 2169 | "We continue with a rudimentary scatter plot example. This example displays samples from the [iris dataset](https://scikit-learn.org/stable/modules/generated/sklearn.datasets.load_iris.html) using the first two features. Colors indicate class membership (there are 3 classes)." 2170 | ] 2171 | }, 2172 | { 2173 | "cell_type": "code", 2174 | "execution_count": null, 2175 | "metadata": { 2176 | "colab": { 2177 | "base_uri": "https://localhost:8080/", 2178 | "height": 268 2179 | }, 2180 | "id": "sEzcJAmy-hbK", 2181 | "outputId": "7d965d22-d0b6-41d5-9f80-f5d6a7d7f93f" 2182 | }, 2183 | "outputs": [ 2184 | { 2185 | "data": { 2186 | "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXUAAAD7CAYAAACVMATUAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2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5Zv4h4DLgNlmdmer45a6qVNZim+Nmb0MfBO40cweH7uDu7/h7u9WHz4MXJ1tiaN1nKz+9zVgN3BN3S5Bi3tnIalWd3/L3d+u/vxtYKaZzcu4zFeAV9z9QPXxLirNc6wY5jSxzkjmc6xbgefc/f9M8FwMc1rTsM5I5vTfAS+5+5C7vwc8CVxXt8/ofFYP0cwB3phs0FI3dXe/x90XuftSKr+Gfcfdx/1LWHe8bw1wLMMSazXMNrNLaz8DNwP/VLdbFIt7h9RqZvNrx/3M7Boqn7NJP4hpc/fTwAkzu7y66SbgR3W75T6nIXXGMJ91NtL4kEbuczpGwzojmdOfAivN7APVWm7i/f1nL/CZ6s+3U+lhk15cFLLwdOmY2X3AoLvvBb5oZmuAC8CbVNIwWfvXwO7qZ2wG8Ffu/jdm9h8husW9Q2q9HfiCmV0AzgEbkj6I0+Q/A09Ufw0/DvxOpHOaVGcs81n7h/zjwH8Ysy26OQ2oM/c5dfcDZraLyqGgC8Ah4MG6/vQI8A0ze5FKf9qQNK6uKBURKZFSH34REWk3auoiIiWipi4iUiJq6iIiJaKmLiJSImrqIiIloqYuIlIiauoiIiXy/wFQN0ndc+l3NAAAAABJRU5ErkJggg==\n", 2187 | "text/plain": [ 2188 | "
" 2189 | ] 2190 | }, 2191 | "metadata": { 2192 | "needs_background": "light", 2193 | "tags": [] 2194 | }, 2195 | "output_type": "display_data" 2196 | } 2197 | ], 2198 | "source": [ 2199 | "from sklearn.datasets import load_iris\n", 2200 | "X, y = load_iris(return_X_y=True)\n", 2201 | "\n", 2202 | "X_class0 = X[y == 0]\n", 2203 | "X_class1 = X[y == 1]\n", 2204 | "X_class2 = X[y == 2]\n", 2205 | "\n", 2206 | "plt.figure()\n", 2207 | "plt.scatter(X_class0[:, 0], X_class0[:, 1], label=\"Class 0\", color=\"C0\")\n", 2208 | "plt.scatter(X_class1[:, 0], X_class1[:, 1], label=\"Class 1\", color=\"C1\")\n", 2209 | "plt.scatter(X_class2[:, 0], X_class2[:, 1], label=\"Class 2\", color=\"C2\")\n", 2210 | "plt.show()" 2211 | ] 2212 | }, 2213 | { 2214 | "cell_type": "markdown", 2215 | "metadata": { 2216 | "id": "5vjln9qwAc3M" 2217 | }, 2218 | "source": [ 2219 | "We see that samples belonging to class 0 can be linearly separated from the rest using only the first two features." 2220 | ] 2221 | }, 2222 | { 2223 | "cell_type": "markdown", 2224 | "metadata": { 2225 | "id": "uVWuIUs2AQ5a" 2226 | }, 2227 | "source": [ 2228 | "## Exercises\n", 2229 | "\n" 2230 | ] 2231 | }, 2232 | { 2233 | "cell_type": "markdown", 2234 | "metadata": { 2235 | "id": "1X6-g6zgCwJd" 2236 | }, 2237 | "source": [ 2238 | "**Exercise 1.** Plot the relu and the [softplus](https://en.wikipedia.org/wiki/Rectifier_(neural_networks)#Softplus) functions on the same graph." 2239 | ] 2240 | }, 2241 | { 2242 | "cell_type": "code", 2243 | "execution_count": null, 2244 | "metadata": { 2245 | "id": "Ob6HZUX0DJ8y" 2246 | }, 2247 | "outputs": [], 2248 | "source": [] 2249 | }, 2250 | { 2251 | "cell_type": "markdown", 2252 | "metadata": { 2253 | "id": "vpRGfz0aDW3l" 2254 | }, 2255 | "source": [ 2256 | "What is the main difference between the two functions?" 2257 | ] 2258 | }, 2259 | { 2260 | "cell_type": "markdown", 2261 | "metadata": { 2262 | "id": "JjDeIufRAYVL" 2263 | }, 2264 | "source": [ 2265 | "**Exercise 2.** Repeat the same scatter plot but using the [digits dataset](https://scikit-learn.org/stable/modules/generated/sklearn.datasets.load_digits.html) instead." 2266 | ] 2267 | }, 2268 | { 2269 | "cell_type": "code", 2270 | "execution_count": null, 2271 | "metadata": { 2272 | "id": "-JU3TXCBBB0c" 2273 | }, 2274 | "outputs": [], 2275 | "source": [ 2276 | "from sklearn.datasets import load_digits\n", 2277 | "X, y = load_digits(return_X_y=True)" 2278 | ] 2279 | }, 2280 | { 2281 | "cell_type": "markdown", 2282 | "metadata": { 2283 | "id": "w7wPWdmXBQA2" 2284 | }, 2285 | "source": [ 2286 | "Are pixel values good features for classifying samples?" 2287 | ] 2288 | }, 2289 | { 2290 | "cell_type": "markdown", 2291 | "metadata": { 2292 | "id": "dYM-oV1jD3RV" 2293 | }, 2294 | "source": [ 2295 | "## Going further\n", 2296 | "\n", 2297 | "* Official [tutorial](https://matplotlib.org/tutorials/introductory/pyplot.html)\n" 2298 | ] 2299 | } 2300 | ], 2301 | "metadata": { 2302 | "colab": { 2303 | "include_colab_link": true, 2304 | "name": " Python basics", 2305 | "provenance": [] 2306 | }, 2307 | "kernelspec": { 2308 | "display_name": "Python 3 (ipykernel)", 2309 | "language": "python", 2310 | "name": "python3" 2311 | }, 2312 | "language_info": { 2313 | "codemirror_mode": { 2314 | "name": "ipython", 2315 | "version": 3 2316 | }, 2317 | "file_extension": ".py", 2318 | "mimetype": "text/x-python", 2319 | "name": "python", 2320 | "nbconvert_exporter": "python", 2321 | "pygments_lexer": "ipython3", 2322 | "version": "3.9.7" 2323 | } 2324 | }, 2325 | "nbformat": 4, 2326 | "nbformat_minor": 1 2327 | } 2328 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | **Python Interview Questions** 2 | 3 | 1. Differentiate between lists and tuples. 4 | 2. What are negative indices? 5 | 3. How long can an identifier be in Python? 6 | 4. How would you convert a string into lowercase? 7 | 5. What is the pass statement in Python? 8 | 6. Explain help() and dir() functions in Python. 9 | 7. How do you get a list of all the keys in a dictionary? 10 | 8. What is slicing? 11 | 9. How would you declare a comment in Python? 12 | 10. How will you check if all characters in a string are alphanumeric? 13 | 11. How will you capitalize the first letter of a string? 14 | 12. With Python, how do you find out which directory you are currently in? 15 | 13. How do you insert an object at a given index in Python? 16 | 14. How do you reverse a list? 17 | 15. What is the Python interpreter prompt? 18 | 16. How does a function return values? 19 | 17. How would you define a block in Python? 20 | 18. Why do we need break and continue in Python? 21 | 19. In one line, show us how you’ll get the max alphabetical character from a string. 22 | 20. Can you name ten built-in functions in Python and explain each in brief? 23 | 21. How will you convert a list into a string? 24 | 22. How will you remove a duplicate element from a list? 25 | 23. What is a dictionary in Python? 26 | 24. Explain the //, %, and ** operators in Python. 27 | 25. What do you know about relational operators in Python. 28 | 26. What are assignment operators in Python? 29 | 27. Explain logical operators in Python. 30 | 28. Finally, tell us about bitwise operators in Python. 31 | 29. What data types does Python support? 32 | 30. How would you convert a string into an int in Python? 33 | 31. How do you take input in Python? 34 | 32. What is recursion? 35 | 33. What does the function zip() do? 36 | 34. How do you calculate the length of a string? 37 | 35. Explain Python List Comprehension. 38 | 36. How do you get all values from a Python dictionary? 39 | 37. What if you want to toggle case for a Python string? 40 | 38. Write code to print everything in the string except the spaces. 41 | 39. Now, print this string five times in a row. 42 | 40. What is the purpose of bytes() in Python? 43 | 41. What is a control flow statement? 44 | 42. Create a new list to convert the following list of number strings to a list of numbers. 45 | 43. Given the first and last names of all employees in your firm, what data type will you use to store it? 46 | 44. How would you work with numbers other than those in the decimal number system? 47 | 45. How many arguments can the range() function take? 48 | 46. What is PEP 8? 49 | 47. What is the best code you can write to swap two numbers? 50 | 48. How can you declare multiple assignments in one statement? 51 | 49. If you are ever stuck in an infinite loop, how will you break out of it? 52 | 50. What are the benefits of using Python? 53 | 51. What are python modules? Name some commonly used built-in modules in Python? 54 | 52. What are local variables and global variables in Python? 55 | 53. What is a lambda function? 56 | 54. What is self in Python? 57 | 55. How does break, continue and pass work? 58 | 56. What does [::-1} do? 59 | 57. How can you generate random numbers in Python? 60 | 58. What is the difference between range & xrange? 61 | 59. How do you write comments in python? 62 | 60. How to add values to a python array? 63 | 61. What are Python libraries? Name a few of them. 64 | 62. How are classes created in Python?  65 | 63. What does an object() do? 66 | 64. Write a program to produce Fibonacci series in Python. 67 | 65. Write a program in Python to check if a number is prime. 68 | 66. Write a program in Python to check if a sequence is a Palindrome. 69 | 67. Write a one-liner that will count the number of capital letters in a file. Your code should work even if the file is too big to fit in memory. 70 | 68. Write a sorting algorithm for a numerical dataset in Python. 71 | 69. What is PYTHON PATH? 72 | 70. What type of language is python? 73 | -------------------------------------------------------------------------------- /python_tutorial.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dsmentors/Python_study_Materials/b08d5764384676003138d2463d6dfcd9eef528c1/python_tutorial.pdf --------------------------------------------------------------------------------