From f5bd38c11d731dea6c9aa8cf608509572c98c5db Mon Sep 17 00:00:00 2001 From: Ivan Morozov Date: Mon, 18 Nov 2019 01:07:05 +0300 Subject: [PATCH] Descrition fix --- 1. Introduction to Numpy.ipynb | 428 +++++++-------------------------- 1 file changed, 91 insertions(+), 337 deletions(-) diff --git a/1. Introduction to Numpy.ipynb b/1. Introduction to Numpy.ipynb index 3103cf2..427b597 100644 --- a/1. Introduction to Numpy.ipynb +++ b/1. Introduction to Numpy.ipynb @@ -3,6 +3,7 @@ { "cell_type": "markdown", "metadata": {}, + "outputs": [], "source": [ "# 1. Introduction to Numpy\n", "Numpy is a Library in python that specializes in dealing with multidimensional Arrays. The cool features of Numpy are\n", @@ -13,7 +14,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 23, "metadata": {}, "outputs": [], "source": [ @@ -24,6 +25,7 @@ { "cell_type": "markdown", "metadata": {}, + "outputs": [], "source": [ "## 1.1 Initialization of 1D array in Python\n", "A numpy array comes with 2 important state variables. Just like Python, it automatically detects dtype (if not mentioned)\n", @@ -36,20 +38,13 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 24, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", - "text": [ - "1D array in numpy is [1 4 9 3 2]\n", - "\n", - "dtype of the numpy array is int32\n", - "\n", - "shape of the numpy array is 5\n", - "\n" - ] + "text": "1D array in numpy is [1 4 9 3 2]\n\ndtype of the numpy array is int64\n\nshape of the numpy array is 5\n\n" } ], "source": [ @@ -63,27 +58,21 @@ { "cell_type": "markdown", "metadata": {}, + "outputs": [], "source": [ "#### 1.1.2 Initialization via arange\n", - "numpy.arange(**\\[**start, **\\]**stop, **\\[**step, **\\]** dtype=None)" + "numpy.arange(**[**start, stop, step**]** dtype=None)" ] }, { "cell_type": "code", - "execution_count": 22, + "execution_count": 25, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", - "text": [ - "Creating a numpy array via arange (stop=5) : [0 1 2 3 4]\n", - "\n", - "Creating a numpy array via arange (start=2,stop=5) : [2 3 4]\n", - "\n", - "Creating a numpy array via arange (start=0,stop=-10,step=-2) : [ 0 -2 -4 -6 -8]\n", - "\n" - ] + "text": "Creating a numpy array via arange (stop=5) : [0 1 2 3 4]\n\nCreating a numpy array via arange (start=2,stop=5) : [2 3 4]\n\nCreating a numpy array via arange (start=0,stop=-10,step=-2) : [ 0 -2 -4 -6 -8]\n\n" } ], "source": [ @@ -99,6 +88,7 @@ { "cell_type": "markdown", "metadata": {}, + "outputs": [], "source": [ "## 1.2. Initialization of 2D array in Python\n", "When we talk about 2D array, it is important to note that Numpy stores Matrix is ***Row Major Format***. Row major format means that the the complete row will be stored first and then the next row will be stored and so on. You can choose to store a matrix in colum major format by mentioning ***order='F'*** on ndarray creation, which means ***Column Major Format*** or *Fortran Style Format*. \n", @@ -109,6 +99,7 @@ { "cell_type": "markdown", "metadata": {}, + "outputs": [], "source": [ "#### 1.2.1 Initialization from List of List\n", "numpy.array **(** ***object***, dtype=None **)**\n", @@ -119,20 +110,13 @@ }, { "cell_type": "code", - "execution_count": 31, + "execution_count": 26, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", - "text": [ - "numpy matrix is \n", - "[[1 2 3]\n", - " [4 5 6]]\n", - "\n", - "Flattened version of numpy matrix is [1 2 3 4 5 6]\n", - "\n" - ] + "text": "numpy matrix is \n[[1 2 3]\n [4 5 6]]\n\nFlattened version of numpy matrix is [1 2 3 4 5 6]\n\n" } ], "source": [ @@ -146,6 +130,7 @@ { "cell_type": "markdown", "metadata": {}, + "outputs": [], "source": [ "#### 1.2.2 Initialization with zero/ones\n", "numpy.**zeros**(*shape*, dtype=float) \n", @@ -154,23 +139,13 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 27, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", - "text": [ - "Zeros Matris of shape (3, 5) is \n", - "[[0. 0. 0. 0. 0.]\n", - " [0. 0. 0. 0. 0.]\n", - " [0. 0. 0. 0. 0.]]\n", - "\n", - "Ones Matris of shape (2, 3) is \n", - "[[1. 1. 1.]\n", - " [1. 1. 1.]]\n", - "\n" - ] + "text": "Zeros Matris of shape (3, 5) is \n[[0. 0. 0. 0. 0.]\n [0. 0. 0. 0. 0.]\n [0. 0. 0. 0. 0.]]\n\nOnes Matris of shape (2, 3) is \n[[1. 1. 1.]\n [1. 1. 1.]]\n\n" } ], "source": [ @@ -183,6 +158,7 @@ { "cell_type": "markdown", "metadata": {}, + "outputs": [], "source": [ "#### 1.2.3 Initialization with Random Values\n", "**1.2.3.1** numpy.**random.random**(*size=None*,) \n", @@ -192,29 +168,13 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 28, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", - "text": [ - "matrix generated from numpy.random.random is \n", - "[[0.40809381 0.92255528 0.26384768 0.18020434]\n", - " [0.78683826 0.51616332 0.20181108 0.44676456]\n", - " [0.40513581 0.41943719 0.14935848 0.49202397]]\n", - "\n", - "matrix generated from numpy.random.random is \n", - "[[1 0 1 0]\n", - " [0 1 1 1]\n", - " [0 1 1 0]]\n", - "\n", - "matrix generated from numpy.random.randn is \n", - "[[ 1.23093258 0.06762907 1.32948035 1.27069921]\n", - " [-1.55068329 -0.48071094 0.85203508 -1.90068409]\n", - " [-1.94335643 0.12680395 0.06573786 -0.66923407]]\n", - "\n" - ] + "text": "matrix generated from numpy.random.random is \n[[0.88543299 0.67887968 0.13098948 0.80490301]\n [0.38677641 0.73885941 0.68558157 0.89456218]\n [0.92253817 0.90720942 0.72966413 0.70287455]]\n\nmatrix generated from numpy.random.random is \n[[0 1 1 0]\n [0 1 0 1]\n [0 1 1 0]]\n\nmatrix generated from numpy.random.randn is \n[[-1.5733044 0.48966842 -0.74037554 0.62584237]\n [ 0.65956069 -0.31941405 -1.05914627 -0.21062263]\n [-2.46230796 0.32617736 0.60196332 1.36276872]]\n\n" } ], "source": [ @@ -230,9 +190,10 @@ { "cell_type": "markdown", "metadata": {}, + "outputs": [], "source": [ "## 1.3. Slicing and Indexing in Numpy\n", - "Just like python, numpy also has 0 indexing. Let us see some of the commonly used slicing techniques . \n", + "Just like python, numpy also has 0 indexing. Let us see some of the commonly used slicing techniques. \n", "* Generic Slicing Operation : \\[start\\]:\\[end\\]:\\[jump\\]\n", "* Only jump **::2**\n", "* Only end **:5**\n", @@ -253,11 +214,7 @@ { "name": "stdout", "output_type": "stream", - "text": [ - "Result of removing last 3 elements from range(10) : \n", - "[0 1 2 3 4 5 6]\n", - "\n" - ] + "text": "Result of removing last 3 elements from range(10) : \n[0 1 2 3 4 5 6]\n\n" } ], "source": [ @@ -269,25 +226,21 @@ { "cell_type": "markdown", "metadata": {}, + "outputs": [], "source": [ "#### 1.3.2 Access elements at even indices in a 1D array\n", - "vec[::2]" + "vec\\[::**2**\\]" ] }, { "cell_type": "code", - "execution_count": 87, + "execution_count": 30, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", - "text": [ - "Original array is [ 0 3 6 9 12 15 18]\n", - "\n", - "Elements at even indices are [ 0 6 12 18]\n", - "\n" - ] + "text": "Original array is [ 0 3 6 9 12 15 18]\n\nElements at even indices are [ 0 6 12 18]\n\n" } ], "source": [ @@ -301,25 +254,21 @@ { "cell_type": "markdown", "metadata": {}, + "outputs": [], "source": [ "#### 1.3.3 Access elements at indices in reverse order\n", - "vec[::-1]" + "vec\\[::**-1**\\]" ] }, { "cell_type": "code", - "execution_count": 88, + "execution_count": 31, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", - "text": [ - "Original array is [ 0 3 6 9 12 15 18]\n", - "\n", - "Elements for indices in reverse is [18 15 12 9 6 3 0]\n", - "\n" - ] + "text": "Original array is [ 0 3 6 9 12 15 18]\n\nElements for indices in reverse is [18 15 12 9 6 3 0]\n\n" } ], "source": [ @@ -332,25 +281,21 @@ { "cell_type": "markdown", "metadata": {}, + "outputs": [], "source": [ "#### 1.3.4 Access elements present for a range of indices\n", - "vec[a:b]" + "vec\\[**a**:**b**\\]" ] }, { "cell_type": "code", - "execution_count": 92, + "execution_count": 32, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", - "text": [ - "Original array is [ 0 3 6 9 12 15 18]\n", - "\n", - "Elements for indices 2:5 is [ 6 9 12]\n", - "\n" - ] + "text": "Original array is [ 0 3 6 9 12 15 18]\n\nElements for indices 2:5 is [ 6 9 12]\n\n" } ], "source": [ @@ -363,25 +308,21 @@ { "cell_type": "markdown", "metadata": {}, + "outputs": [], "source": [ "#### 1.3.5 Access a particular set of index given by a list\n", - "vec[idxlist]" + "vec\\[**idxlist**\\]" ] }, { "cell_type": "code", - "execution_count": 95, + "execution_count": 33, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", - "text": [ - "Original array is [ 0 3 6 9 12 15 18]\n", - "\n", - "Subarray constructed by indices [0, 1, 5] is [ 0 3 15]\n", - "\n" - ] + "text": "Original array is [ 0 3 6 9 12 15 18]\n\nSubarray constructed by indices [0, 1, 5] is [ 0 3 15]\n\n" } ], "source": [ @@ -395,34 +336,20 @@ { "cell_type": "markdown", "metadata": {}, + "outputs": [], "source": [ "#### 1.3.6 Creating a submatrix" ] }, { "cell_type": "code", - "execution_count": 109, + "execution_count": 34, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", - "text": [ - "Original Matrix is \n", - "[[1 2 0 0 2]\n", - " [4 1 5 3 2]\n", - " [2 1 3 5 0]]\n", - "\n", - "Sub Matrix with first 2 rows and last 2 columns is \n", - "[[0 2]\n", - " [3 2]]\n", - "\n", - "After flipping the columns of the matrix, it looks : \n", - "[[0 0 2]\n", - " [3 5 1]\n", - " [5 3 1]]\n", - "\n" - ] + "text": "Original Matrix is \n[[1 2 1 2 2]\n [1 2 3 1 4]\n [0 0 1 1 3]]\n\nSub Matrix with first 2 rows and last 2 columns is \n[[2 2]\n [1 4]]\n\nAfter flipping the columns of the matrix, it looks : \n[[2 2 1 2 1]\n [4 1 3 2 1]\n [3 1 1 0 0]]\n\n" } ], "source": [ @@ -431,13 +358,14 @@ "submat1 = mat[0:2,-2:]\n", "print ('Original Matrix is \\n%s\\n'%mat)\n", "print ('Sub Matrix with first 2 rows and last 2 columns is \\n%s\\n'%submat1)\n", - "submat2 = mat[:,3:0:-1]\n", + "submat2 = mat[:,::-1]\n", "print ('After flipping the columns of the matrix, it looks : \\n%s\\n'%submat2)" ] }, { "cell_type": "markdown", "metadata": {}, + "outputs": [], "source": [ "#### 1.3.7 Horizontal Matrix splitting\n", "numpy.**hsplit**(ary, *indices_or_sections*) \n", @@ -449,34 +377,13 @@ }, { "cell_type": "code", - "execution_count": 131, + "execution_count": 35, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", - "text": [ - "Original matrix of shape (3, 7), is \n", - "[[5 4 1 2 1 5 2]\n", - " [1 5 5 5 0 5 3]\n", - " [2 0 1 5 4 4 4]]\n", - "\n", - "First split of shape (3, 4), is \n", - "[[5 4 1 2]\n", - " [1 5 5 5]\n", - " [2 0 1 5]]\n", - "\n", - "Second split of shape (3, 2), is \n", - "[[1 5]\n", - " [0 5]\n", - " [4 4]]\n", - "\n", - "Third split of shape (3, 1), is \n", - "[[2]\n", - " [3]\n", - " [4]]\n", - "\n" - ] + "text": "Original matrix of shape (3, 7), is \n[[0 5 5 3 2 4 4]\n [1 1 2 2 3 2 2]\n [1 5 1 5 0 4 3]]\n\nFirst split of shape (3, 4), is \n[[0 5 5 3]\n [1 1 2 2]\n [1 5 1 5]]\n\nSecond split of shape (3, 2), is \n[[2 4]\n [3 2]\n [0 4]]\n\nThird split of shape (3, 1), is \n[[4]\n [2]\n [3]]\n\n" } ], "source": [ @@ -491,6 +398,7 @@ { "cell_type": "markdown", "metadata": {}, + "outputs": [], "source": [ "#### 1.3.8 Vertical Matrix Splitting\n", "numpy.**vsplit**(ary, *indices_or_sections*) \n", @@ -500,26 +408,13 @@ }, { "cell_type": "code", - "execution_count": 134, + "execution_count": 36, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", - "text": [ - "Original matrix of shape (3, 7), is \n", - "[[5 2 1 1 0 5 5]\n", - " [5 3 0 1 5 2 1]\n", - " [5 5 4 2 2 1 0]]\n", - "\n", - "First split of shape (1, 7), is \n", - "[[5 2 1 1 0 5 5]]\n", - "\n", - "Second split of shape (2, 7), is \n", - "[[5 3 0 1 5 2 1]\n", - " [5 5 4 2 2 1 0]]\n", - "\n" - ] + "text": "Original matrix of shape (3, 7), is \n[[4 4 0 5 5 3 5]\n [0 0 0 3 2 2 1]\n [3 3 4 3 1 0 0]]\n\nFirst split of shape (1, 7), is \n[[4 4 0 5 5 3 5]]\n\nSecond split of shape (2, 7), is \n[[0 0 0 3 2 2 1]\n [3 3 4 3 1 0 0]]\n\n" } ], "source": [ @@ -533,9 +428,10 @@ { "cell_type": "markdown", "metadata": {}, + "outputs": [], "source": [ "> ### *Class Assignment for 1.1 to 1.3*\n", - ">\n", + "\n", "> 1. Create a matrix of size (2,3) with random binary values\n", "> 2. Find the sum of all 2x2 blocks (overlapping) for a random integer matrix of size (3,5) " ] @@ -543,6 +439,7 @@ { "cell_type": "markdown", "metadata": {}, + "outputs": [], "source": [ "## 1.4. Understanding - Pass By Reference \n", "Just like python lists, Numpy also exhibits default pass-by-reference behavior\n", @@ -551,21 +448,13 @@ }, { "cell_type": "code", - "execution_count": 110, + "execution_count": 37, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", - "text": [ - "Memory Location of mat1[0] is : 2041724279440\n", - "\n", - "Memory Location of mat1[1] is : 2041724279464\n", - "\n", - "Difference in Memory Location for 3 elements is : 24 bytes\n", - "\n", - "Memory jump = 8 bytes\n" - ] + "text": "Memory Location of mat1[0] is : 94576342424512\n\nMemory Location of mat1[1] is : 94576342424536\n\nDifference in Memory Location for 3 elements is : 24 bytes\n\nMemory jump = 8 bytes\n" } ], "source": [ @@ -581,26 +470,20 @@ { "cell_type": "markdown", "metadata": {}, + "outputs": [], "source": [ "#### 1.4.1 Experiment : Change the value of array by Reference" ] }, { "cell_type": "code", - "execution_count": 117, + "execution_count": 38, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", - "text": [ - "Value of v, after v1 is modified is [10 2 3]\n", - "\n", - "Value of v after func(v) is modified is [10 2 3]\n", - "\n", - "Value of v after v.copy() is modified is [1 2 3]\n", - "\n" - ] + "text": "Value of v, after v1 is modified is [10 2 3]\n\nValue of v after func(v) is modified is [10 2 3]\n\nValue of v after v.copy() is modified is [1 2 3]\n\n" } ], "source": [ @@ -624,29 +507,20 @@ { "cell_type": "markdown", "metadata": {}, + "outputs": [], "source": [ "#### 1.4.2 Experiment : Change the value of matrices by Reference" ] }, { "cell_type": "code", - "execution_count": 136, + "execution_count": 39, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", - "text": [ - "Original Matrix is \n", - "[[1 2 3]\n", - " [4 5 6]\n", - " [7 8 9]]\n", - "\n", - " Matrix with 10 added to even indices is \n", - "[[11 13]\n", - " [17 19]]\n", - "\n" - ] + "text": "Original Matrix is \n[[1 2 3]\n [4 5 6]\n [7 8 9]]\n\n Matrix with 10 added to even indices is \n[[11 13]\n [17 19]]\n\n" } ], "source": [ @@ -656,7 +530,7 @@ "#1 Add 10 to all the even indexes in matrix\n", "mat = np.array([[1,2,3],[4,5,6],[7,8,9]])\n", "mat1 = mat[::2,::2]\n", - "mat1+=10\n", + "mat1 += 10\n", "print (' Matrix with 10 added to even indices is \\n%s\\n'%mat1)\n", "# Changes in mat1 are reflected in mat. This happens because the default assignment in numpy is 'pass by reference'" ] @@ -664,13 +538,15 @@ { "cell_type": "markdown", "metadata": {}, + "outputs": [], "source": [ - "> **Note :** mat1+=10 is different from mat1=mat1+10, as a new space is allocated for mat1 in the latter case." + "> **Note :** mat1+=10 is different from mat1 = mat1+10, as a new space is allocated for mat1 in the latter case." ] }, { "cell_type": "markdown", "metadata": {}, + "outputs": [], "source": [ "## 1.5 Broadcast Operation in Numpy\n", "Broadcast Operation is like a razor-sharp knife, to be used with great care. It is a way to ***broadcast*** data of lower or same dimension onto another ndarray. It is similar to ***map*** operation in python, scala, hadoop. Broadcast rules are not limited to 2D array. There are extremely specific set of rules for nd-array broadcasting. You can visit ***[numpy documentation on broadcasting](https://docs.scipy.org/doc/numpy-1.13.0/user/basics.broadcasting.html)*** to get the complete picture. However, we will be restricting the discussion to only 2D-matrices.\n", @@ -680,47 +556,13 @@ }, { "cell_type": "code", - "execution_count": 147, + "execution_count": 40, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", - "text": [ - "mat is \n", - "[[1 1 2 1 4]\n", - " [4 2 1 3 5]\n", - " [3 1 1 2 5]]\n", - "\n", - "v is \n", - "[10 20 30 40 50]\n", - "\n", - "mat+1 is \n", - "[[2 2 3 2 5]\n", - " [5 3 2 4 6]\n", - " [4 2 2 3 6]]\n", - "\n", - "mat+v is \n", - "[[11 21 32 41 54]\n", - " [14 22 31 43 55]\n", - " [13 21 31 42 55]]\n", - "\n", - "mat*v is \n", - "[[ 10 20 60 40 200]\n", - " [ 40 40 30 120 250]\n", - " [ 30 20 30 80 250]]\n", - "\n", - "mat+mat is \n", - "[[ 2 2 4 2 8]\n", - " [ 8 4 2 6 10]\n", - " [ 6 2 2 4 10]]\n", - "\n", - "mat*mat is \n", - "[[ 1 1 4 1 16]\n", - " [16 4 1 9 25]\n", - " [ 9 1 1 4 25]]\n", - "\n" - ] + "text": "mat is \n[[2 5 0 0 0]\n [5 3 4 1 2]\n [0 1 2 2 0]]\n\nv is \n[10 20 30 40 50]\n\nmat+1 is \n[[3 6 1 1 1]\n [6 4 5 2 3]\n [1 2 3 3 1]]\n\nmat+v is \n[[12 25 30 40 50]\n [15 23 34 41 52]\n [10 21 32 42 50]]\n\nmat*v is \n[[ 20 100 0 0 0]\n [ 50 60 120 40 100]\n [ 0 20 60 80 0]]\n\nmat+mat is \n[[ 4 10 0 0 0]\n [10 6 8 2 4]\n [ 0 2 4 4 0]]\n\nmat*mat is \n[[ 4 25 0 0 0]\n [25 9 16 1 4]\n [ 0 1 4 4 0]]\n\n" } ], "source": [ @@ -738,9 +580,11 @@ { "cell_type": "markdown", "metadata": {}, + "outputs": [], "source": [ "## 1.6 Matrix Operations \n", "There are two major matix Operations which are important for us.\n", + "\n", "1. Inner Product\n", " * Vector Vector\n", " * Matrix Vector \n", @@ -760,49 +604,13 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 41, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", - "text": [ - "Vector v1 is [1 2 3]\n", - "\n", - "Vector v2 is [2 4 6]\n", - "\n", - "Vector Vector dot product is is 28\n", - "\n", - "---------------\n", - "\n", - "Matrix is\n", - "[[0 1 2]\n", - " [3 4 5]\n", - " [6 7 8]]\n", - "\n", - "Vector v2 is\n", - "[1 2 3]\n", - "\n", - "Matrix Vector product is is \n", - "[ 8 26 44]\n", - "\n", - "Matrix Matrix multiplication is is \n", - "[[ 15 18 21]\n", - " [ 42 54 66]\n", - " [ 69 90 111]]\n", - "\n", - "---------------\n", - "\n", - "Vector v1 is [1 2 3]\n", - "\n", - "Vector v2 is [2 4 6]\n", - "\n", - "Vector Vector outer product is is \n", - "[[ 2 4 6]\n", - " [ 4 8 12]\n", - " [ 6 12 18]]\n", - "\n" - ] + "text": "Vector v1 is [1 2 3]\n\nVector v2 is [2 4 6]\n\nVector Vector dot product is is 28\n\n---------------\n\nMatrix is\n[[0 1 2]\n [3 4 5]\n [6 7 8]]\n\nVector v2 is\n[1 2 3]\n\nMatrix Vector product is is \n[ 8 26 44]\n\nMatrix Matrix multiplication is is \n[[ 15 18 21]\n [ 42 54 66]\n [ 69 90 111]]\n\n---------------\n\nVector v1 is [1 2 3]\n\nVector v2 is [2 4 6]\n\nVector Vector outer product is is \n[[ 2 4 6]\n [ 4 8 12]\n [ 6 12 18]]\n\n" } ], "source": [ @@ -829,56 +637,26 @@ { "cell_type": "markdown", "metadata": {}, + "outputs": [], "source": [ "## 1.7 Statistical Functions\n", - "1. **np.mean**(data,axis=0)\n", - "2. **np.var**(data,axis=0)\n", - "3. **np.sum**(data,axis=0)\n", - "4. **np.max**(data,axis=0)\n", - "5. **np.min**(data,axis=0)\n", - "6. **np.percentile**(data, percentage,axis=0)" + "1. np.**mean**(data,axis=0)\n", + "2. np.**var**(data,axis=0)\n", + "3. np.**sum**(data,axis=0)\n", + "4. np.**max**(data,axis=0)\n", + "5. np.**min**(data,axis=0)\n", + "6. np.**percentile**(data, percentage,axis=0)" ] }, { "cell_type": "code", - "execution_count": 40, + "execution_count": 42, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", - "text": [ - "Original matrix is \n", - "[[0 1 2]\n", - " [3 4 5]\n", - " [6 7 8]]\n", - "\n", - "Overall mean of matrix is \n", - "4.0\n", - "\n", - "Row mean of matrix is \n", - "[3. 4. 5.]\n", - "\n", - "Column mean of matrix is \n", - "[1. 4. 7.]\n", - "\n", - "---------------------------\n", - "\n", - "Overall varience of matrix is 6.666666666666667\n", - "\n", - "Overall sum of matrix is 36\n", - "\n", - "Overall min of matrix is 0\n", - "\n", - "Overall max of matrix is 8\n", - "\n", - "-------------------------------------\n", - "\n", - "Marks = [ 30 31 32 40 90 95 97 98 99 100]\n", - "\n", - "Overall 30 percent quantile of marks is 37.599999999999994\n", - "\n" - ] + "text": "Original matrix is \n[[0 1 2]\n [3 4 5]\n [6 7 8]]\n\nOverall mean of matrix is \n4.0\n\nRow mean of matrix is \n[3. 4. 5.]\n\nColumn mean of matrix is \n[1. 4. 7.]\n\n---------------------------\n\nOverall varience of matrix is 6.666666666666667\n\nOverall sum of matrix is 36\n\nOverall min of matrix is 0\n\nOverall max of matrix is 8\n\n-------------------------------------\n\nMarks = [ 30 31 32 40 90 95 97 98 99 100]\n\nOverall 30 percent quantile of marks is 37.599999999999994\n\n" } ], "source": [ @@ -903,30 +681,25 @@ { "cell_type": "markdown", "metadata": {}, + "outputs": [], "source": [ "## 1.8 Miscellenous Functions\n", "In this section, we will be discussing some important miscellenous Functions which come in handy for matrix manipulation.\n", "#### 1.8.1 squeeze\n", - "numpy.**squeeze**(a,axis=None) \n", + "numpy.**squeeze**(a,axis=None)\n", + " \n", "This function tries to reduce the excess dimensions which have only 1 element. If we print the shape of the ndary, these excess dimension will have a 1 in that particular dimension's index. For example, a nd-matrix with shape (1,2,3,1), has $0^{th}$ and $3^{rd}$ dimension as excess." ] }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 43, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", - "text": [ - "Original Shape of ndmat is (1, 2, 3, 1)\n", - "\n", - "Shape of np.squeeze(ndmat) is (2, 3)\n", - "\n", - "Shape of np.squeeze(ndmat,axis=3) is (1, 2, 3)\n", - "\n" - ] + "text": "Original Shape of ndmat is (1, 2, 3, 1)\n\nShape of np.squeeze(ndmat) is (2, 3)\n\nShape of np.squeeze(ndmat,axis=3) is (1, 2, 3)\n\n" } ], "source": [ @@ -942,37 +715,24 @@ { "cell_type": "markdown", "metadata": {}, + "outputs": [], "source": [ "#### 1.8.2 transpose\n", - "numpy.**transpose**(a, *axes=None*) \n", + "numpy.**transpose**(a, *axes=None*) \n", + " \n", "This function reverses the axes for 2D array. \n", - "For multidimensional array, it permutes the matrix according to the axis argument" + "For multidimensional array, it permutes the matrix according to the axis argument.\n" ] }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 44, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", - "text": [ - "Original Shape of 2D matrix is (2, 3)\n", - "\n", - "Shape of np.transpose(mat) is (3, 2)\n", - "\n", - "np.transpose is by yet again assignment by reference, as changes in transpose reflects in the original matrix\n", - "\n", - "---------------------------------\n", - "\n", - "Original Shape of nDimensional matrix is (2, 3, 4)\n", - "\n", - "Shape of np.transpose(ndmat) is (4, 3, 2)\n", - "\n", - "Shape of np.transpose(ndmat, axes=[0,2,1]) is (2, 4, 3)\n", - "\n" - ] + "text": "Original Shape of 2D matrix is (2, 3)\n\nShape of np.transpose(mat) is (3, 2)\n\nnp.transpose is by yet again assignment by reference, as changes in transpose reflects in the original matrix\n\n---------------------------------\n\nOriginal Shape of nDimensional matrix is (2, 3, 4)\n\nShape of np.transpose(ndmat) is (4, 3, 2)\n\nShape of np.transpose(ndmat, axes=[0,2,1]) is (2, 4, 3)\n\n" } ], "source": [ @@ -992,16 +752,10 @@ "print ('Shape of np.transpose(ndmat, axes=[0,2,1]) is %s\\n'%str(ndmat_special_transpose.shape))\n" ] }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - }, { "cell_type": "markdown", "metadata": {}, + "outputs": [], "source": [ "# Chapter 1 Assignment\n", "1. Create a null array of size 10 but the fifth value which is 1\n", @@ -1053,4 +807,4 @@ }, "nbformat": 4, "nbformat_minor": 2 -} +} \ No newline at end of file