├── .ipynb_checkpoints └── Numpy-checkpoint.ipynb ├── LICENSE ├── Numpy.ipynb └── README.md /.ipynb_checkpoints/Numpy-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Numpy\n", 8 | "\n", 9 | "This notebook includes a collection of commands and functions provided in the Numpy library that are really useful and speed up the data manipulation instructions." 10 | ] 11 | }, 12 | { 13 | "cell_type": "markdown", 14 | "metadata": {}, 15 | "source": [ 16 | "## Import Numpy\n", 17 | "I first begin by importing the nump library. I use the Python generic notation to import it and I rename it as `np` so I can use `np` instead of `numpy` everywhere." 18 | ] 19 | }, 20 | { 21 | "cell_type": "code", 22 | "execution_count": 30, 23 | "metadata": {}, 24 | "outputs": [], 25 | "source": [ 26 | "import numpy as np" 27 | ] 28 | }, 29 | { 30 | "cell_type": "markdown", 31 | "metadata": {}, 32 | "source": [ 33 | "# Numpy array\n", 34 | "I begin by first creating a numpy array and then accessing its elements using the index values." 35 | ] 36 | }, 37 | { 38 | "cell_type": "code", 39 | "execution_count": 32, 40 | "metadata": {}, 41 | "outputs": [ 42 | { 43 | "name": "stdout", 44 | "output_type": "stream", 45 | "text": [ 46 | "1\n", 47 | "[1 2]\n" 48 | ] 49 | }, 50 | { 51 | "data": { 52 | "text/plain": [ 53 | "True" 54 | ] 55 | }, 56 | "execution_count": 32, 57 | "metadata": {}, 58 | "output_type": "execute_result" 59 | } 60 | ], 61 | "source": [ 62 | "# Define an array arr with integer elements 1,2,3 and 4\n", 63 | "integerArray = np.array([1,2,3,4], int)\n", 64 | "\n", 65 | "# We can access these elements by using index values\n", 66 | "print(integerArray[0])\n", 67 | "\n", 68 | "# We can also use ranges to access values\n", 69 | "print(integerArray[:2])\n", 70 | "\n", 71 | "# Find if a value exists in the array\n", 72 | "# Returns true if value exists else returns false\n", 73 | "2 in integerArray # Returns true" 74 | ] 75 | }, 76 | { 77 | "cell_type": "markdown", 78 | "metadata": {}, 79 | "source": [ 80 | "Numpy also provides quick methods to define an array. Basic methods include:\n", 81 | "1. concatenation - combine arrays\n", 82 | "2. zeros - array with all values zero\n", 83 | "3. ones - array with all values one\n", 84 | "4. range - define the array as a range of values" 85 | ] 86 | }, 87 | { 88 | "cell_type": "code", 89 | "execution_count": 33, 90 | "metadata": {}, 91 | "outputs": [ 92 | { 93 | "name": "stdout", 94 | "output_type": "stream", 95 | "text": [ 96 | "[1 2 3 4 5 6]\n", 97 | "[0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]\n", 98 | "[1 1 1 1 1 1 1 1 1 1]\n", 99 | "[0 1 2 3 4 5 6 7 8 9]\n" 100 | ] 101 | } 102 | ], 103 | "source": [ 104 | "integerArray2 = np.array([5,6], int)\n", 105 | "\n", 106 | "# Concatenate two arrays\n", 107 | "print(np.concatenate((integerArray, integerArray2)))\n", 108 | "\n", 109 | "# Array of zeros\n", 110 | "print(np.zeros(10))\n", 111 | "\n", 112 | "# Array of ones with type int\n", 113 | "print(np.ones(10, dtype=int))\n", 114 | "\n", 115 | "# Range of numbers\n", 116 | "rangeArray = np.array(range(10), int)\n", 117 | "print(rangeArray)" 118 | ] 119 | }, 120 | { 121 | "cell_type": "markdown", 122 | "metadata": {}, 123 | "source": [ 124 | "## Multidimensional arrays\n", 125 | "\n", 126 | "Further, Numpy library also enables us to create multidimensional arrays.\n", 127 | "Moreover, the `reshape` function allows us to convert Numpy single dimensional arrays to multidimensional arrays and vice versa using `flatten`." 128 | ] 129 | }, 130 | { 131 | "cell_type": "code", 132 | "execution_count": 34, 133 | "metadata": {}, 134 | "outputs": [ 135 | { 136 | "name": "stdout", 137 | "output_type": "stream", 138 | "text": [ 139 | "[[1. 2. 3.]\n", 140 | " [4. 5. 6.]]\n", 141 | "[[0 1]\n", 142 | " [2 3]\n", 143 | " [4 5]\n", 144 | " [6 7]\n", 145 | " [8 9]]\n", 146 | "[0 1 2 3 4 5 6 7 8 9]\n" 147 | ] 148 | } 149 | ], 150 | "source": [ 151 | "# Multidimensional array\n", 152 | "floatArray = np.array([[1,2,3], [4,5,6]], float)\n", 153 | "print(floatArray)\n", 154 | "\n", 155 | "# Convert one dimensional to multi-dimensional arrays\n", 156 | "rangeArray = rangeArray.reshape(5, 2)\n", 157 | "print(rangeArray)\n", 158 | "# and vice versa too\n", 159 | "rangeArray = rangeArray.flatten()\n", 160 | "print(rangeArray)" 161 | ] 162 | }, 163 | { 164 | "cell_type": "markdown", 165 | "metadata": {}, 166 | "source": [ 167 | "`Concatenate` function on multidimensional arrays can be performed on any axis. For a two dimensional array (array[row][column]), to concatenate along row, we set axis as 0 (default is also 0). To concatenate along column, we set axis to 1." 168 | ] 169 | }, 170 | { 171 | "cell_type": "code", 172 | "execution_count": 35, 173 | "metadata": {}, 174 | "outputs": [ 175 | { 176 | "name": "stdout", 177 | "output_type": "stream", 178 | "text": [ 179 | "[[1 2]\n", 180 | " [3 4]\n", 181 | " [5 6]\n", 182 | " [7 8]]\n", 183 | "[[1 2]\n", 184 | " [3 4]\n", 185 | " [5 6]\n", 186 | " [7 8]]\n", 187 | "[[1 2 5 6]\n", 188 | " [3 4 7 8]]\n" 189 | ] 190 | } 191 | ], 192 | "source": [ 193 | "# Concatenation of multi-dimensional arrays\n", 194 | "arr1 = np.array([[1,2], [3,4]], int)\n", 195 | "arr2 = np.array([[5,6], [7,8]], int)\n", 196 | "print(np.concatenate((arr1, arr2)))\n", 197 | "\n", 198 | "# Based on dimension 1\n", 199 | "print(np.concatenate((arr1, arr2), axis=0))\n", 200 | "\n", 201 | "# Based on dimension 2\n", 202 | "print(np.concatenate((arr1, arr2), axis=1))" 203 | ] 204 | }, 205 | { 206 | "cell_type": "markdown", 207 | "metadata": {}, 208 | "source": [ 209 | "## Numpy array operations\n", 210 | "Numpy arrays allow us to directly apply a range of operations such as addition, subtraction etc. The operators are overloaded in the library which makes the process possible. The operations occur on an element by element basis." 211 | ] 212 | }, 213 | { 214 | "cell_type": "code", 215 | "execution_count": 43, 216 | "metadata": {}, 217 | "outputs": [ 218 | { 219 | "name": "stdout", 220 | "output_type": "stream", 221 | "text": [ 222 | "Array 1\n", 223 | " [[1 2]\n", 224 | " [3 4]]\n", 225 | "Array 2\n", 226 | " [[5 6]\n", 227 | " [7 8]]\n", 228 | "Array 1 + Array 2\n", 229 | " [[ 6 8]\n", 230 | " [10 12]]\n", 231 | "Array 1 * Array 2\n", 232 | " [[ 5 12]\n", 233 | " [21 32]]\n", 234 | "Square root of Array 1\n", 235 | " [[1. 1.41421356]\n", 236 | " [1.73205081 2. ]]\n", 237 | "Square root of Array 1\n", 238 | " [[0. 0.69314718]\n", 239 | " [1.09861229 1.38629436]]\n" 240 | ] 241 | } 242 | ], 243 | "source": [ 244 | "print(\"Array 1\\n {}\".format(arr1))\n", 245 | "print(\"Array 2\\n {}\".format(arr2))\n", 246 | "\n", 247 | "# Addition\n", 248 | "print(\"Array 1 + Array 2\\n {}\".format(arr1 + arr2))\n", 249 | "\n", 250 | "# Multiplication\n", 251 | "print(\"Array 1 * Array 2\\n {}\".format(arr1 * arr2))\n", 252 | "\n", 253 | "# Square root\n", 254 | "print(\"Square root of Array 1\\n {}\".format(np.sqrt(arr1)))\n", 255 | "\n", 256 | "# Log\n", 257 | "print(\"Log of Array 1\\n {}\".format(np.log(arr1)))" 258 | ] 259 | }, 260 | { 261 | "cell_type": "markdown", 262 | "metadata": {}, 263 | "source": [ 264 | "However, these opertations will throw errors if the dimensions of the arrays are not same. There are many other operations that are available to us such as `exp`, `floor`, `abs` and many trignometric funcitons.\n", 265 | "\n", 266 | "Operations can be specific to a given array too such as sum of all elements of the array and others. If we define the axis, then we can calculate the operations across the respective row or column." 267 | ] 268 | }, 269 | { 270 | "cell_type": "code", 271 | "execution_count": 60, 272 | "metadata": {}, 273 | "outputs": [ 274 | { 275 | "name": "stdout", 276 | "output_type": "stream", 277 | "text": [ 278 | "Sum of elements of Array 1: 10\n", 279 | "Mean of elements of Array 1: 2.5\n", 280 | "Minimum of elements of Array 1: 1\n", 281 | "Index of minimum of elements of Array 1: 3\n" 282 | ] 283 | } 284 | ], 285 | "source": [ 286 | "# Sum of array elements\n", 287 | "print(\"Sum of elements of Array 1: {}\".format(arr1.sum()))\n", 288 | "\n", 289 | "# Mean of array elements\n", 290 | "print(\"Mean of elements of Array 1: {}\".format(arr1.mean()))\n", 291 | "# We can also calulate variance using var() and standard deviation using std()\n", 292 | "\n", 293 | "# Minimum of array elements\n", 294 | "print(\"Minimum of elements of Array 1: {}\".format(arr1.min()))\n", 295 | "# We can also calculate maximum value using max()\n", 296 | "\n", 297 | "# Index of maximum of array elements can be found using arg before the funciton name\n", 298 | "print(\"Index of minimum of elements of Array 1: {}\".format(arr1.argmax()))\n", 299 | "# We can also find index of minimum value using argmin()" 300 | ] 301 | }, 302 | { 303 | "cell_type": "code", 304 | "execution_count": 61, 305 | "metadata": {}, 306 | "outputs": [ 307 | { 308 | "name": "stdout", 309 | "output_type": "stream", 310 | "text": [ 311 | "Sample Array\n", 312 | " [[5 2 3]\n", 313 | " [3 4 5]\n", 314 | " [1 1 1]]\n", 315 | "Unique values: [1 2 3 4 5]\n", 316 | "Diagonal\n", 317 | " [5 4 1]\n", 318 | "Sorted\n", 319 | " [[2 3 5]\n", 320 | " [3 4 5]\n", 321 | " [1 1 1]]\n" 322 | ] 323 | } 324 | ], 325 | "source": [ 326 | "sampleArray = np.array([[5,2,3], [3,4,5], [1,1,1]], int)\n", 327 | "print(\"Sample Array\\n {}\".format(sampleArray))\n", 328 | "\n", 329 | "# Get unqiue values\n", 330 | "print(\"Unique values: {}\".format(np.unique(sampleArray)))\n", 331 | "\n", 332 | "# Get diagonal values\n", 333 | "print(\"Diagonal\\n {}\".format(sampleArray.diagonal()))\n", 334 | "\n", 335 | "# Sort values in the multidimensional array\n", 336 | "print(\"Sorted\\n {}\".format(np.sort(sampleArray)))" 337 | ] 338 | }, 339 | { 340 | "cell_type": "markdown", 341 | "metadata": {}, 342 | "source": [ 343 | "## Compare arrays\n", 344 | "We can also use comparison operators to compare complete arrays with one another" 345 | ] 346 | }, 347 | { 348 | "cell_type": "code", 349 | "execution_count": 50, 350 | "metadata": {}, 351 | "outputs": [ 352 | { 353 | "name": "stdout", 354 | "output_type": "stream", 355 | "text": [ 356 | "Array 1 > Array 2\n", 357 | "[[False False]\n", 358 | " [False False]]\n", 359 | "Array 1 == 2\n", 360 | " [[False True]\n", 361 | " [False False]]\n" 362 | ] 363 | } 364 | ], 365 | "source": [ 366 | "# We can compare complete arrays of equal size element wise\n", 367 | "print(\"Array 1 > Array 2\\n{}\".format(arr1 > arr2))\n", 368 | "\n", 369 | "# We can compare elements of an array with a given value\n", 370 | "print(\"Array 1 == 2\\n {}\".format(arr1 == 2))" 371 | ] 372 | }, 373 | { 374 | "cell_type": "markdown", 375 | "metadata": {}, 376 | "source": [ 377 | "## Vector and Matrix operations\n", 378 | "Numpy is specifically famous for its efficiency while working with vectors and matrices. Some of the useful functions are described here." 379 | ] 380 | }, 381 | { 382 | "cell_type": "code", 383 | "execution_count": 64, 384 | "metadata": {}, 385 | "outputs": [ 386 | { 387 | "name": "stdout", 388 | "output_type": "stream", 389 | "text": [ 390 | "Dot of Matrix 1 and Matrix 2\n", 391 | " [[ 4 4 4]\n", 392 | " [10 10 10]\n", 393 | " [16 16 16]]\n", 394 | "Cross of Matrix 1 and Matrix 2\n", 395 | " [[-1 2 -1]\n", 396 | " [ 0 0 0]\n", 397 | " [-1 2 -1]]\n", 398 | "Outer of Matrix 1 and Matrix 2\n", 399 | " [[1 1 1 0 0 0 1 1 1]\n", 400 | " [2 2 2 0 0 0 2 2 2]\n", 401 | " [3 3 3 0 0 0 3 3 3]\n", 402 | " [4 4 4 0 0 0 4 4 4]\n", 403 | " [5 5 5 0 0 0 5 5 5]\n", 404 | " [6 6 6 0 0 0 6 6 6]\n", 405 | " [7 7 7 0 0 0 7 7 7]\n", 406 | " [8 8 8 0 0 0 8 8 8]\n", 407 | " [9 9 9 0 0 0 9 9 9]]\n", 408 | "Inner of Matrix 1 and Matrix 2\n", 409 | " [[ 6 0 6]\n", 410 | " [15 0 15]\n", 411 | " [24 0 24]]\n" 412 | ] 413 | } 414 | ], 415 | "source": [ 416 | "vector = np.array([1,2,3,4], int)\n", 417 | "matrix1 = np.array([[1,2,3], [4,5,6], [7,8,9]], int)\n", 418 | "matrix2 = np.array([[1,1,1], [0,0,0], [1,1,1]], int)\n", 419 | "\n", 420 | "# Dot operator\n", 421 | "print(\"Dot of Matrix 1 and Matrix 2\\n {}\".format(np.dot(matrix1, matrix2)))\n", 422 | "\n", 423 | "# Cross operator\n", 424 | "print(\"Cross of Matrix 1 and Matrix 2\\n {}\".format(np.cross(matrix1, matrix2)))\n", 425 | "\n", 426 | "# Outer operator\n", 427 | "print(\"Outer of Matrix 1 and Matrix 2\\n {}\".format(np.outer(matrix1, matrix2)))\n", 428 | "\n", 429 | "# Inner operator\n", 430 | "print(\"Inner of Matrix 1 and Matrix 2\\n {}\".format(np.inner(matrix1, matrix2)))" 431 | ] 432 | }, 433 | { 434 | "cell_type": "markdown", 435 | "metadata": {}, 436 | "source": [ 437 | "## Random array\n", 438 | "We can use the random function to get arrays with random values." 439 | ] 440 | }, 441 | { 442 | "cell_type": "code", 443 | "execution_count": 80, 444 | "metadata": {}, 445 | "outputs": [ 446 | { 447 | "name": "stdout", 448 | "output_type": "stream", 449 | "text": [ 450 | "Random array: [0.76073446 0.99345894 0.46903477 0.84603991 0.38853774]\n", 451 | "Random matrix:\n", 452 | " [[0.16632713 0.58049315 0.34176713 0.94322875]\n", 453 | " [0.22748443 0.82143576 0.81514027 0.29211289]\n", 454 | " [0.96835549 0.89565579 0.48977925 0.83669168]\n", 455 | " [0.41939199 0.76978422 0.85281824 0.26429364]\n", 456 | " [0.40808517 0.33635079 0.34038655 0.9892858 ]]\n", 457 | "Random integer array: [9. 3. 5. 7. 4. 7. 8. 8. 9. 4.]\n", 458 | "Random matrix:\n", 459 | "[[5 3 0 2 9]\n", 460 | " [0 4 4 7 8]]\n" 461 | ] 462 | } 463 | ], 464 | "source": [ 465 | "# Random array\n", 466 | "print(\"Random array: {}\".format(np.random.rand(5)))\n", 467 | "\n", 468 | "# Random matrix\n", 469 | "print(\"Random matrix:\\n {}\".format(np.random.rand(5,4)))\n", 470 | "\n", 471 | "# Random array of integers in a range (say 0-9)\n", 472 | "randomArray = np.floor(np.random.rand(10) * 10)\n", 473 | "print(\"Random integer array: {}\".format(randomArray))\n", 474 | "\n", 475 | "# Futher simplification\n", 476 | "print(\"Random matrix:\\n{}\".format(np.random.randint(0, 10, (2,5))))" 477 | ] 478 | }, 479 | { 480 | "cell_type": "markdown", 481 | "metadata": {}, 482 | "source": [ 483 | "# Numpy Strategies\n", 484 | "There are a total of 4 startegies to consider in the Numpy library that can help us work better with loops.\n", 485 | "These include:\n", 486 | "1. Universal Functions\n", 487 | "2. Aggregations\n", 488 | "3. Broadcasting\n", 489 | "4. Slicing, masking and fancy indexing\n", 490 | "\n", 491 | "I've already adressed them in the examples above but here I would create the exact distinctions.\n", 492 | "These functions are essential as they are very quick in their operation." 493 | ] 494 | }, 495 | { 496 | "cell_type": "markdown", 497 | "metadata": {}, 498 | "source": [ 499 | "## Universal Functions\n", 500 | "These functions operate element-wise on the elements of an array." 501 | ] 502 | }, 503 | { 504 | "cell_type": "code", 505 | "execution_count": 107, 506 | "metadata": {}, 507 | "outputs": [ 508 | { 509 | "name": "stdout", 510 | "output_type": "stream", 511 | "text": [ 512 | "Array: [0 1 2 3 4 5 6 7 8 9]\n", 513 | "New array: [ 0 10 20 30 40 50 60 70 80 90]\n" 514 | ] 515 | } 516 | ], 517 | "source": [ 518 | "# Multiply all elements of an array by 10\n", 519 | "arr = np.array(range(10), int)\n", 520 | "print(\"Array: {}\".format(arr))\n", 521 | "print(\"New array: {}\".format(arr * 10))" 522 | ] 523 | }, 524 | { 525 | "cell_type": "markdown", 526 | "metadata": {}, 527 | "source": [ 528 | "## Aggregation Functions\n", 529 | "These functions summarize the information contained in an array." 530 | ] 531 | }, 532 | { 533 | "cell_type": "code", 534 | "execution_count": 92, 535 | "metadata": {}, 536 | "outputs": [ 537 | { 538 | "name": "stdout", 539 | "output_type": "stream", 540 | "text": [ 541 | "Standard deviation of array: 2.8722813232690143\n" 542 | ] 543 | } 544 | ], 545 | "source": [ 546 | "# Get standard deviation of all array values\n", 547 | "print(\"Standard deviation of array: {}\".format(arr.std()))" 548 | ] 549 | }, 550 | { 551 | "cell_type": "markdown", 552 | "metadata": {}, 553 | "source": [ 554 | "## Broadcasting\n", 555 | "This defines the rules of how universal functions operate on arrays. This determines how a number might be added to a matrix, how a vector gets added to a matrix etc. \n", 556 | "It broadcasts the smaller of the two to match the bigger so the operation may be performed." 557 | ] 558 | }, 559 | { 560 | "cell_type": "code", 561 | "execution_count": 93, 562 | "metadata": {}, 563 | "outputs": [ 564 | { 565 | "name": "stdout", 566 | "output_type": "stream", 567 | "text": [ 568 | "Final sum after broadcasting:\n", 569 | " [[ 2 3 4]\n", 570 | " [10 9 8]]\n" 571 | ] 572 | } 573 | ], 574 | "source": [ 575 | "# Add a row to a matrix\n", 576 | "mat = np.array([[1,2,3], [9,8,7]], int)\n", 577 | "arr = np.array([1,1,1], int)\n", 578 | "# On adding the two, arr will get broadcasted and will get added as a matrix with both rows same as [1,1,1]\n", 579 | "print(\"Final sum after broadcasting:\\n {}\".format(mat + arr))" 580 | ] 581 | }, 582 | { 583 | "cell_type": "markdown", 584 | "metadata": {}, 585 | "source": [ 586 | "## Slicing, masking and fancy indexing\n", 587 | "We can slice numpy arrays as and where needed or maybe get values based on index." 588 | ] 589 | }, 590 | { 591 | "cell_type": "code", 592 | "execution_count": 108, 593 | "metadata": {}, 594 | "outputs": [ 595 | { 596 | "name": "stdout", 597 | "output_type": "stream", 598 | "text": [ 599 | "Array: [0 1 2 3 4 5 6 7 8 9]\n", 600 | "Array value from index 0 to 4: [0 1 2 3 4]\n", 601 | "[ True True True False False False False True True True]\n", 602 | "Array values with mask as true: [0 1 2 7 8 9]\n", 603 | "Array values with index in list: [2 4 6]\n", 604 | "Array values with index in list: [7]\n" 605 | ] 606 | } 607 | ], 608 | "source": [ 609 | "bigArray = np.array(range(10))\n", 610 | "print(\"Array: {}\".format(bigArray))\n", 611 | "\n", 612 | "# Slice array from index 0 to 4\n", 613 | "print(\"Array value from index 0 to 4: {}\".format(bigArray[:5]))\n", 614 | "\n", 615 | "# Masking using boolean values and operators\n", 616 | "mask = (bigArray > 6) | (bigArray < 3)\n", 617 | "print(\"Array values with mask as true: {}\".format(bigArray[mask]))\n", 618 | "\n", 619 | "# Fancy indexing\n", 620 | "ind = [2,4,6]\n", 621 | "print(\"Array values with index in list: {}\".format(bigArray[ind]))\n", 622 | "\n", 623 | "# Combine all three\n", 624 | "print(\"Array values with index in list: {}\".format(bigArray[bigArray > 6][:1]))" 625 | ] 626 | }, 627 | { 628 | "cell_type": "markdown", 629 | "metadata": {}, 630 | "source": [ 631 | "# Conclusion\n", 632 | "Here, I have worked with a few key functions available in Numpy that facilitate array, vector and matrix multiplication. This understanding was essential as it is the basis for many other libraries such as Sklearn which uses Numpy for its algorithms." 633 | ] 634 | } 635 | ], 636 | "metadata": { 637 | "kernelspec": { 638 | "display_name": "Python 3", 639 | "language": "python", 640 | "name": "python3" 641 | }, 642 | "language_info": { 643 | "codemirror_mode": { 644 | "name": "ipython", 645 | "version": 3 646 | }, 647 | "file_extension": ".py", 648 | "mimetype": "text/x-python", 649 | "name": "python", 650 | "nbconvert_exporter": "python", 651 | "pygments_lexer": "ipython3", 652 | "version": "3.6.5" 653 | } 654 | }, 655 | "nbformat": 4, 656 | "nbformat_minor": 2 657 | } 658 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Karan Bhanot 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Numpy.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Numpy\n", 8 | "\n", 9 | "This notebook includes a collection of commands and functions provided in the Numpy library that are really useful and speed up the data manipulation instructions." 10 | ] 11 | }, 12 | { 13 | "cell_type": "markdown", 14 | "metadata": {}, 15 | "source": [ 16 | "## Import Numpy\n", 17 | "I first begin by importing the nump library. I use the Python generic notation to import it and I rename it as `np` so I can use `np` instead of `numpy` everywhere." 18 | ] 19 | }, 20 | { 21 | "cell_type": "code", 22 | "execution_count": 30, 23 | "metadata": {}, 24 | "outputs": [], 25 | "source": [ 26 | "import numpy as np" 27 | ] 28 | }, 29 | { 30 | "cell_type": "markdown", 31 | "metadata": {}, 32 | "source": [ 33 | "# Numpy array\n", 34 | "I begin by first creating a numpy array and then accessing its elements using the index values." 35 | ] 36 | }, 37 | { 38 | "cell_type": "code", 39 | "execution_count": 32, 40 | "metadata": {}, 41 | "outputs": [ 42 | { 43 | "name": "stdout", 44 | "output_type": "stream", 45 | "text": [ 46 | "1\n", 47 | "[1 2]\n" 48 | ] 49 | }, 50 | { 51 | "data": { 52 | "text/plain": [ 53 | "True" 54 | ] 55 | }, 56 | "execution_count": 32, 57 | "metadata": {}, 58 | "output_type": "execute_result" 59 | } 60 | ], 61 | "source": [ 62 | "# Define an array arr with integer elements 1,2,3 and 4\n", 63 | "integerArray = np.array([1,2,3,4], int)\n", 64 | "\n", 65 | "# We can access these elements by using index values\n", 66 | "print(integerArray[0])\n", 67 | "\n", 68 | "# We can also use ranges to access values\n", 69 | "print(integerArray[:2])\n", 70 | "\n", 71 | "# Find if a value exists in the array\n", 72 | "# Returns true if value exists else returns false\n", 73 | "2 in integerArray # Returns true" 74 | ] 75 | }, 76 | { 77 | "cell_type": "markdown", 78 | "metadata": {}, 79 | "source": [ 80 | "Numpy also provides quick methods to define an array. Basic methods include:\n", 81 | "1. concatenation - combine arrays\n", 82 | "2. zeros - array with all values zero\n", 83 | "3. ones - array with all values one\n", 84 | "4. range - define the array as a range of values" 85 | ] 86 | }, 87 | { 88 | "cell_type": "code", 89 | "execution_count": 33, 90 | "metadata": {}, 91 | "outputs": [ 92 | { 93 | "name": "stdout", 94 | "output_type": "stream", 95 | "text": [ 96 | "[1 2 3 4 5 6]\n", 97 | "[0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]\n", 98 | "[1 1 1 1 1 1 1 1 1 1]\n", 99 | "[0 1 2 3 4 5 6 7 8 9]\n" 100 | ] 101 | } 102 | ], 103 | "source": [ 104 | "integerArray2 = np.array([5,6], int)\n", 105 | "\n", 106 | "# Concatenate two arrays\n", 107 | "print(np.concatenate((integerArray, integerArray2)))\n", 108 | "\n", 109 | "# Array of zeros\n", 110 | "print(np.zeros(10))\n", 111 | "\n", 112 | "# Array of ones with type int\n", 113 | "print(np.ones(10, dtype=int))\n", 114 | "\n", 115 | "# Range of numbers\n", 116 | "rangeArray = np.array(range(10), int)\n", 117 | "print(rangeArray)" 118 | ] 119 | }, 120 | { 121 | "cell_type": "markdown", 122 | "metadata": {}, 123 | "source": [ 124 | "## Multidimensional arrays\n", 125 | "\n", 126 | "Further, Numpy library also enables us to create multidimensional arrays.\n", 127 | "Moreover, the `reshape` function allows us to convert Numpy single dimensional arrays to multidimensional arrays and vice versa using `flatten`." 128 | ] 129 | }, 130 | { 131 | "cell_type": "code", 132 | "execution_count": 34, 133 | "metadata": {}, 134 | "outputs": [ 135 | { 136 | "name": "stdout", 137 | "output_type": "stream", 138 | "text": [ 139 | "[[1. 2. 3.]\n", 140 | " [4. 5. 6.]]\n", 141 | "[[0 1]\n", 142 | " [2 3]\n", 143 | " [4 5]\n", 144 | " [6 7]\n", 145 | " [8 9]]\n", 146 | "[0 1 2 3 4 5 6 7 8 9]\n" 147 | ] 148 | } 149 | ], 150 | "source": [ 151 | "# Multidimensional array\n", 152 | "floatArray = np.array([[1,2,3], [4,5,6]], float)\n", 153 | "print(floatArray)\n", 154 | "\n", 155 | "# Convert one dimensional to multi-dimensional arrays\n", 156 | "rangeArray = rangeArray.reshape(5, 2)\n", 157 | "print(rangeArray)\n", 158 | "# and vice versa too\n", 159 | "rangeArray = rangeArray.flatten()\n", 160 | "print(rangeArray)" 161 | ] 162 | }, 163 | { 164 | "cell_type": "markdown", 165 | "metadata": {}, 166 | "source": [ 167 | "`Concatenate` function on multidimensional arrays can be performed on any axis. For a two dimensional array (array[row][column]), to concatenate along row, we set axis as 0 (default is also 0). To concatenate along column, we set axis to 1." 168 | ] 169 | }, 170 | { 171 | "cell_type": "code", 172 | "execution_count": 35, 173 | "metadata": {}, 174 | "outputs": [ 175 | { 176 | "name": "stdout", 177 | "output_type": "stream", 178 | "text": [ 179 | "[[1 2]\n", 180 | " [3 4]\n", 181 | " [5 6]\n", 182 | " [7 8]]\n", 183 | "[[1 2]\n", 184 | " [3 4]\n", 185 | " [5 6]\n", 186 | " [7 8]]\n", 187 | "[[1 2 5 6]\n", 188 | " [3 4 7 8]]\n" 189 | ] 190 | } 191 | ], 192 | "source": [ 193 | "# Concatenation of multi-dimensional arrays\n", 194 | "arr1 = np.array([[1,2], [3,4]], int)\n", 195 | "arr2 = np.array([[5,6], [7,8]], int)\n", 196 | "print(np.concatenate((arr1, arr2)))\n", 197 | "\n", 198 | "# Based on dimension 1\n", 199 | "print(np.concatenate((arr1, arr2), axis=0))\n", 200 | "\n", 201 | "# Based on dimension 2\n", 202 | "print(np.concatenate((arr1, arr2), axis=1))" 203 | ] 204 | }, 205 | { 206 | "cell_type": "markdown", 207 | "metadata": {}, 208 | "source": [ 209 | "## Numpy array operations\n", 210 | "Numpy arrays allow us to directly apply a range of operations such as addition, subtraction etc. The operators are overloaded in the library which makes the process possible. The operations occur on an element by element basis." 211 | ] 212 | }, 213 | { 214 | "cell_type": "code", 215 | "execution_count": 43, 216 | "metadata": {}, 217 | "outputs": [ 218 | { 219 | "name": "stdout", 220 | "output_type": "stream", 221 | "text": [ 222 | "Array 1\n", 223 | " [[1 2]\n", 224 | " [3 4]]\n", 225 | "Array 2\n", 226 | " [[5 6]\n", 227 | " [7 8]]\n", 228 | "Array 1 + Array 2\n", 229 | " [[ 6 8]\n", 230 | " [10 12]]\n", 231 | "Array 1 * Array 2\n", 232 | " [[ 5 12]\n", 233 | " [21 32]]\n", 234 | "Square root of Array 1\n", 235 | " [[1. 1.41421356]\n", 236 | " [1.73205081 2. ]]\n", 237 | "Square root of Array 1\n", 238 | " [[0. 0.69314718]\n", 239 | " [1.09861229 1.38629436]]\n" 240 | ] 241 | } 242 | ], 243 | "source": [ 244 | "print(\"Array 1\\n {}\".format(arr1))\n", 245 | "print(\"Array 2\\n {}\".format(arr2))\n", 246 | "\n", 247 | "# Addition\n", 248 | "print(\"Array 1 + Array 2\\n {}\".format(arr1 + arr2))\n", 249 | "\n", 250 | "# Multiplication\n", 251 | "print(\"Array 1 * Array 2\\n {}\".format(arr1 * arr2))\n", 252 | "\n", 253 | "# Square root\n", 254 | "print(\"Square root of Array 1\\n {}\".format(np.sqrt(arr1)))\n", 255 | "\n", 256 | "# Log\n", 257 | "print(\"Log of Array 1\\n {}\".format(np.log(arr1)))" 258 | ] 259 | }, 260 | { 261 | "cell_type": "markdown", 262 | "metadata": {}, 263 | "source": [ 264 | "However, these opertations will throw errors if the dimensions of the arrays are not same. There are many other operations that are available to us such as `exp`, `floor`, `abs` and many trignometric funcitons.\n", 265 | "\n", 266 | "Operations can be specific to a given array too such as sum of all elements of the array and others. If we define the axis, then we can calculate the operations across the respective row or column." 267 | ] 268 | }, 269 | { 270 | "cell_type": "code", 271 | "execution_count": 60, 272 | "metadata": {}, 273 | "outputs": [ 274 | { 275 | "name": "stdout", 276 | "output_type": "stream", 277 | "text": [ 278 | "Sum of elements of Array 1: 10\n", 279 | "Mean of elements of Array 1: 2.5\n", 280 | "Minimum of elements of Array 1: 1\n", 281 | "Index of minimum of elements of Array 1: 3\n" 282 | ] 283 | } 284 | ], 285 | "source": [ 286 | "# Sum of array elements\n", 287 | "print(\"Sum of elements of Array 1: {}\".format(arr1.sum()))\n", 288 | "\n", 289 | "# Mean of array elements\n", 290 | "print(\"Mean of elements of Array 1: {}\".format(arr1.mean()))\n", 291 | "# We can also calulate variance using var() and standard deviation using std()\n", 292 | "\n", 293 | "# Minimum of array elements\n", 294 | "print(\"Minimum of elements of Array 1: {}\".format(arr1.min()))\n", 295 | "# We can also calculate maximum value using max()\n", 296 | "\n", 297 | "# Index of maximum of array elements can be found using arg before the funciton name\n", 298 | "print(\"Index of minimum of elements of Array 1: {}\".format(arr1.argmax()))\n", 299 | "# We can also find index of minimum value using argmin()" 300 | ] 301 | }, 302 | { 303 | "cell_type": "code", 304 | "execution_count": 61, 305 | "metadata": {}, 306 | "outputs": [ 307 | { 308 | "name": "stdout", 309 | "output_type": "stream", 310 | "text": [ 311 | "Sample Array\n", 312 | " [[5 2 3]\n", 313 | " [3 4 5]\n", 314 | " [1 1 1]]\n", 315 | "Unique values: [1 2 3 4 5]\n", 316 | "Diagonal\n", 317 | " [5 4 1]\n", 318 | "Sorted\n", 319 | " [[2 3 5]\n", 320 | " [3 4 5]\n", 321 | " [1 1 1]]\n" 322 | ] 323 | } 324 | ], 325 | "source": [ 326 | "sampleArray = np.array([[5,2,3], [3,4,5], [1,1,1]], int)\n", 327 | "print(\"Sample Array\\n {}\".format(sampleArray))\n", 328 | "\n", 329 | "# Get unqiue values\n", 330 | "print(\"Unique values: {}\".format(np.unique(sampleArray)))\n", 331 | "\n", 332 | "# Get diagonal values\n", 333 | "print(\"Diagonal\\n {}\".format(sampleArray.diagonal()))\n", 334 | "\n", 335 | "# Sort values in the multidimensional array\n", 336 | "print(\"Sorted\\n {}\".format(np.sort(sampleArray)))" 337 | ] 338 | }, 339 | { 340 | "cell_type": "markdown", 341 | "metadata": {}, 342 | "source": [ 343 | "## Compare arrays\n", 344 | "We can also use comparison operators to compare complete arrays with one another" 345 | ] 346 | }, 347 | { 348 | "cell_type": "code", 349 | "execution_count": 50, 350 | "metadata": {}, 351 | "outputs": [ 352 | { 353 | "name": "stdout", 354 | "output_type": "stream", 355 | "text": [ 356 | "Array 1 > Array 2\n", 357 | "[[False False]\n", 358 | " [False False]]\n", 359 | "Array 1 == 2\n", 360 | " [[False True]\n", 361 | " [False False]]\n" 362 | ] 363 | } 364 | ], 365 | "source": [ 366 | "# We can compare complete arrays of equal size element wise\n", 367 | "print(\"Array 1 > Array 2\\n{}\".format(arr1 > arr2))\n", 368 | "\n", 369 | "# We can compare elements of an array with a given value\n", 370 | "print(\"Array 1 == 2\\n {}\".format(arr1 == 2))" 371 | ] 372 | }, 373 | { 374 | "cell_type": "markdown", 375 | "metadata": {}, 376 | "source": [ 377 | "## Vector and Matrix operations\n", 378 | "Numpy is specifically famous for its efficiency while working with vectors and matrices. Some of the useful functions are described here." 379 | ] 380 | }, 381 | { 382 | "cell_type": "code", 383 | "execution_count": 64, 384 | "metadata": {}, 385 | "outputs": [ 386 | { 387 | "name": "stdout", 388 | "output_type": "stream", 389 | "text": [ 390 | "Dot of Matrix 1 and Matrix 2\n", 391 | " [[ 4 4 4]\n", 392 | " [10 10 10]\n", 393 | " [16 16 16]]\n", 394 | "Cross of Matrix 1 and Matrix 2\n", 395 | " [[-1 2 -1]\n", 396 | " [ 0 0 0]\n", 397 | " [-1 2 -1]]\n", 398 | "Outer of Matrix 1 and Matrix 2\n", 399 | " [[1 1 1 0 0 0 1 1 1]\n", 400 | " [2 2 2 0 0 0 2 2 2]\n", 401 | " [3 3 3 0 0 0 3 3 3]\n", 402 | " [4 4 4 0 0 0 4 4 4]\n", 403 | " [5 5 5 0 0 0 5 5 5]\n", 404 | " [6 6 6 0 0 0 6 6 6]\n", 405 | " [7 7 7 0 0 0 7 7 7]\n", 406 | " [8 8 8 0 0 0 8 8 8]\n", 407 | " [9 9 9 0 0 0 9 9 9]]\n", 408 | "Inner of Matrix 1 and Matrix 2\n", 409 | " [[ 6 0 6]\n", 410 | " [15 0 15]\n", 411 | " [24 0 24]]\n" 412 | ] 413 | } 414 | ], 415 | "source": [ 416 | "vector = np.array([1,2,3,4], int)\n", 417 | "matrix1 = np.array([[1,2,3], [4,5,6], [7,8,9]], int)\n", 418 | "matrix2 = np.array([[1,1,1], [0,0,0], [1,1,1]], int)\n", 419 | "\n", 420 | "# Dot operator\n", 421 | "print(\"Dot of Matrix 1 and Matrix 2\\n {}\".format(np.dot(matrix1, matrix2)))\n", 422 | "\n", 423 | "# Cross operator\n", 424 | "print(\"Cross of Matrix 1 and Matrix 2\\n {}\".format(np.cross(matrix1, matrix2)))\n", 425 | "\n", 426 | "# Outer operator\n", 427 | "print(\"Outer of Matrix 1 and Matrix 2\\n {}\".format(np.outer(matrix1, matrix2)))\n", 428 | "\n", 429 | "# Inner operator\n", 430 | "print(\"Inner of Matrix 1 and Matrix 2\\n {}\".format(np.inner(matrix1, matrix2)))" 431 | ] 432 | }, 433 | { 434 | "cell_type": "markdown", 435 | "metadata": {}, 436 | "source": [ 437 | "## Random array\n", 438 | "We can use the random function to get arrays with random values." 439 | ] 440 | }, 441 | { 442 | "cell_type": "code", 443 | "execution_count": 80, 444 | "metadata": {}, 445 | "outputs": [ 446 | { 447 | "name": "stdout", 448 | "output_type": "stream", 449 | "text": [ 450 | "Random array: [0.76073446 0.99345894 0.46903477 0.84603991 0.38853774]\n", 451 | "Random matrix:\n", 452 | " [[0.16632713 0.58049315 0.34176713 0.94322875]\n", 453 | " [0.22748443 0.82143576 0.81514027 0.29211289]\n", 454 | " [0.96835549 0.89565579 0.48977925 0.83669168]\n", 455 | " [0.41939199 0.76978422 0.85281824 0.26429364]\n", 456 | " [0.40808517 0.33635079 0.34038655 0.9892858 ]]\n", 457 | "Random integer array: [9. 3. 5. 7. 4. 7. 8. 8. 9. 4.]\n", 458 | "Random matrix:\n", 459 | "[[5 3 0 2 9]\n", 460 | " [0 4 4 7 8]]\n" 461 | ] 462 | } 463 | ], 464 | "source": [ 465 | "# Random array\n", 466 | "print(\"Random array: {}\".format(np.random.rand(5)))\n", 467 | "\n", 468 | "# Random matrix\n", 469 | "print(\"Random matrix:\\n {}\".format(np.random.rand(5,4)))\n", 470 | "\n", 471 | "# Random array of integers in a range (say 0-9)\n", 472 | "randomArray = np.floor(np.random.rand(10) * 10)\n", 473 | "print(\"Random integer array: {}\".format(randomArray))\n", 474 | "\n", 475 | "# Futher simplification\n", 476 | "print(\"Random matrix:\\n{}\".format(np.random.randint(0, 10, (2,5))))" 477 | ] 478 | }, 479 | { 480 | "cell_type": "markdown", 481 | "metadata": {}, 482 | "source": [ 483 | "# Numpy Strategies\n", 484 | "There are a total of 4 startegies to consider in the Numpy library that can help us work better with loops.\n", 485 | "These include:\n", 486 | "1. Universal Functions\n", 487 | "2. Aggregations\n", 488 | "3. Broadcasting\n", 489 | "4. Slicing, masking and fancy indexing\n", 490 | "\n", 491 | "I've already adressed them in the examples above but here I would create the exact distinctions.\n", 492 | "These functions are essential as they are very quick in their operation." 493 | ] 494 | }, 495 | { 496 | "cell_type": "markdown", 497 | "metadata": {}, 498 | "source": [ 499 | "## Universal Functions\n", 500 | "These functions operate element-wise on the elements of an array." 501 | ] 502 | }, 503 | { 504 | "cell_type": "code", 505 | "execution_count": 107, 506 | "metadata": {}, 507 | "outputs": [ 508 | { 509 | "name": "stdout", 510 | "output_type": "stream", 511 | "text": [ 512 | "Array: [0 1 2 3 4 5 6 7 8 9]\n", 513 | "New array: [ 0 10 20 30 40 50 60 70 80 90]\n" 514 | ] 515 | } 516 | ], 517 | "source": [ 518 | "# Multiply all elements of an array by 10\n", 519 | "arr = np.array(range(10), int)\n", 520 | "print(\"Array: {}\".format(arr))\n", 521 | "print(\"New array: {}\".format(arr * 10))" 522 | ] 523 | }, 524 | { 525 | "cell_type": "markdown", 526 | "metadata": {}, 527 | "source": [ 528 | "## Aggregation Functions\n", 529 | "These functions summarize the information contained in an array." 530 | ] 531 | }, 532 | { 533 | "cell_type": "code", 534 | "execution_count": 92, 535 | "metadata": {}, 536 | "outputs": [ 537 | { 538 | "name": "stdout", 539 | "output_type": "stream", 540 | "text": [ 541 | "Standard deviation of array: 2.8722813232690143\n" 542 | ] 543 | } 544 | ], 545 | "source": [ 546 | "# Get standard deviation of all array values\n", 547 | "print(\"Standard deviation of array: {}\".format(arr.std()))" 548 | ] 549 | }, 550 | { 551 | "cell_type": "markdown", 552 | "metadata": {}, 553 | "source": [ 554 | "## Broadcasting\n", 555 | "This defines the rules of how universal functions operate on arrays. This determines how a number might be added to a matrix, how a vector gets added to a matrix etc. \n", 556 | "It broadcasts the smaller of the two to match the bigger so the operation may be performed." 557 | ] 558 | }, 559 | { 560 | "cell_type": "code", 561 | "execution_count": 93, 562 | "metadata": {}, 563 | "outputs": [ 564 | { 565 | "name": "stdout", 566 | "output_type": "stream", 567 | "text": [ 568 | "Final sum after broadcasting:\n", 569 | " [[ 2 3 4]\n", 570 | " [10 9 8]]\n" 571 | ] 572 | } 573 | ], 574 | "source": [ 575 | "# Add a row to a matrix\n", 576 | "mat = np.array([[1,2,3], [9,8,7]], int)\n", 577 | "arr = np.array([1,1,1], int)\n", 578 | "# On adding the two, arr will get broadcasted and will get added as a matrix with both rows same as [1,1,1]\n", 579 | "print(\"Final sum after broadcasting:\\n {}\".format(mat + arr))" 580 | ] 581 | }, 582 | { 583 | "cell_type": "markdown", 584 | "metadata": {}, 585 | "source": [ 586 | "## Slicing, masking and fancy indexing\n", 587 | "We can slice numpy arrays as and where needed or maybe get values based on index." 588 | ] 589 | }, 590 | { 591 | "cell_type": "code", 592 | "execution_count": 109, 593 | "metadata": {}, 594 | "outputs": [ 595 | { 596 | "name": "stdout", 597 | "output_type": "stream", 598 | "text": [ 599 | "Array: [0 1 2 3 4 5 6 7 8 9]\n", 600 | "Array value from index 0 to 4: [0 1 2 3 4]\n", 601 | "Array values with mask as true: [0 1 2 7 8 9]\n", 602 | "Array values with index in list: [2 4 6]\n", 603 | "Array values with index in list: [7]\n" 604 | ] 605 | } 606 | ], 607 | "source": [ 608 | "bigArray = np.array(range(10))\n", 609 | "print(\"Array: {}\".format(bigArray))\n", 610 | "\n", 611 | "# Slice array from index 0 to 4\n", 612 | "print(\"Array value from index 0 to 4: {}\".format(bigArray[:5]))\n", 613 | "\n", 614 | "# Masking using boolean values and operators\n", 615 | "mask = (bigArray > 6) | (bigArray < 3)\n", 616 | "print(\"Array values with mask as true: {}\".format(bigArray[mask]))\n", 617 | "\n", 618 | "# Fancy indexing\n", 619 | "ind = [2,4,6]\n", 620 | "print(\"Array values with index in list: {}\".format(bigArray[ind]))\n", 621 | "\n", 622 | "# Combine all three\n", 623 | "print(\"Array values with index in list: {}\".format(bigArray[bigArray > 6][:1]))" 624 | ] 625 | }, 626 | { 627 | "cell_type": "markdown", 628 | "metadata": {}, 629 | "source": [ 630 | "# Conclusion\n", 631 | "Here, I have worked with a few key functions available in Numpy that facilitate array, vector and matrix multiplication. This understanding was essential as it is the basis for many other libraries such as Sklearn which uses Numpy for its algorithms." 632 | ] 633 | } 634 | ], 635 | "metadata": { 636 | "kernelspec": { 637 | "display_name": "Python 3", 638 | "language": "python", 639 | "name": "python3" 640 | }, 641 | "language_info": { 642 | "codemirror_mode": { 643 | "name": "ipython", 644 | "version": 3 645 | }, 646 | "file_extension": ".py", 647 | "mimetype": "text/x-python", 648 | "name": "python", 649 | "nbconvert_exporter": "python", 650 | "pygments_lexer": "ipython3", 651 | "version": "3.6.5" 652 | } 653 | }, 654 | "nbformat": 4, 655 | "nbformat_minor": 2 656 | } 657 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Understanding-Numpy 2 | 3 | This Github repository includes my understanding of Numpy arrays and various functions that are quite useful. I've created a notebook to reflect and understand the outputs of numerous functions. 4 | 5 | The in-depth explanation of the repository is available on Medium. 6 | --------------------------------------------------------------------------------