‫So in this lecture we'll cover
‫Important libraries of python which is numpy ,Pandas,
‫Seaborn
‫So here we'll
‫Open our Jupiter home screen
‫Click on new Python 3 notebook.
‫First we'll cover the numpy
‫Numpy is the code numerical computing package in Python
‫And its code type is ######
‫Also known as numpy array.
‫You can change the title of notebook
‫And save this
‫Is also an autosave feature in jupyter Notebook
‫So you don't have to worry about saving it.
‫Numpy package is almost used in all numerical computation using python
‫And it provides high performance vector Matrix and higher dimensional data structures for python
‫It is implemented in C and FORTRAN
‫And that's why it is much faster than Python inbuilt function.
‫To use numpy we need to import the module
‫Import the module will write import numpy
‫Snp
‫Since we are using Anaconda there is no need to install this library
‫All the important libraries are already installed using the Anaconda.
‫And if you are using Python you have to use PIP install in the command prompt
‫Install this library.
‫There are various ways to initialize a numpy array
‫We can either convert existing Python list or tuple or we can generate a numpy array
‫Using functions like a range and line space.
‫So let's start with numpy array
‫Will create a variable n p 1 equal to
‫Np.array is a function
‫This function of numpy package that's why we have to write n p
‫So in the first statement we'll
‫Install numpy as NP that's why we have to write NP before every function of this numpy
‫Package that's why I will write NP.array
‫And then in the bracket will input a list
‫As you remember list are
‫Covered by square bracket square bracket we'll write a list 1, 2, 3, 4
‫we enter
‫If we write NP
‫and run this
‫You can see
‫The output is showing us array
‫Which contain element 1 2 3 and 4
‫If we write type of NP one will give us
‫Output that it is a numpy ND array.
‫To create a matrix
‫You have to pass two list
‫its a nested list in which there are two lists so we'll write
‫Mate1 equal to NP array .array
‫Parenthesis will write
‫nested list which contain two lists.
‫If you run this
‫We'll get a matrix.
‫You can see this is a array in which our first floor is this which contains element for 1 and 2 and
‫Second row is 3, 4.
‫Our np1 is an one dimensional array where is ###### one is a two dimensional array
‫Look at the shape of these two arrays will write
‫Mp1.shape
‫Dot shape is a Keyword that will give us the shape of that array.
‫So np1 is our single dimensional array which contains only four elements if we write mate1.shape
‫So you can see that this is a matrix which contain two rows and two columns.
‫Unlike Python list in which you can combine multiple types of element in numpy array
‫You have to insert only similar types of element.
‫Get the type of elements of numpy Array you have to write
‫D type so
‫I write mat 1.Dtype.
‫It will give me the
‫Type of data elements in mat one array
‫You can see
‫The elements are integer
‫I can change the value of element
‫By just using equal to operator so if I write matte one
‫Square bracket so my first element is 0, 0
‫I write 0,0
‫Equal to 5
‫It will assign the first element
‫Value 5
‫Output you can see that first element is now changed to 5 instead of 1 earlier
‫If I try to assign some string value to this array will get an error because
‫As I said earlier
‫All the elements of numpy Array should be of same type.
‫You can see you are getting an error because all the other element are of type integer and we cannot
‫pass
‫A string
‫Element into this numpy array that's why we are getting an error.
‫In list
‫We use the function range
‫to generate
‫Numbers in a sequence.
‫Numpy array
‫We can use function arrange
‫Similarly to generate elements for example
‫If I want
‫New variable Matte 2 equal to
‫Now I want it to start from 0 to 10 with a step of 1 I write Np
‫Dot a range
‫And then the start point Which is zero
‫, the end point which is
‫10
‫Comma ####### which is one
‫I run this
‫You can see that
‫NoW MATTE2 contains
‫All the values from 0 to 9
‫Stopping point is excluded
‫but the starting point is included.
‫Similarly we want to include both the elements both the starting point and stopping point
‫We have to use linspace function.
‫Will write matte3 equal to
‫Np.#######
‫our starting point is zero our ending point is 10 and here instead of steps
‫You have to mention the number of elements we want so if you want 20 elements we have to write 20.
‫if we see
‫We have 20 elements filled between our starting point and ending point.
‫Here the array is coming in the form of matrix
‫But if we find out the shape of this you can see that this is only a one dimensional array.
‫Can see there are 20 elements and this one dimensional array.
‫Now to generate a random matrix
‫You can do that by using NP dot
‫Random
‫.trend
‫Here we have to specify the number of columns ,number of rows
‫Example if we want five rows and five columns we can write 5,5
‫To Do this
‫we'll view our Matrix 4
‫It contain random number between 0 and 1
‫And this is a 5 by 5 matrix.
‫Now if you want a normally distributed
‫Random numbers
‫Can do this by changing
‫Random.#######
‫Again 5,5
‫There are other functions as well to create metrics such as NP diag
‫Create a diagonal Matrix in which only the element of the diagonal have the value
‫Mp.0 will create empty Matrix in which all the elements are zero
‫Np dot one will create a matrix in which all the elements have value 1
‫You are not discussing this right now but you can explode this on your own.
‫Now just like in a list or Strings we can also use slicing using the index now
‫Number
‫So for example if we write
‫Matte 5
‫0, 0
‫It will give me the first element of this Matrix 5
‫if I write
‫matte 5
‫0, 1
‫It will give me the element from the First row that is the zeros
‫with index 0 and the second column that is the column with index one I am getting this value
‫as a output.
‫If I want to select all this value that means all the values from
‫First 3 rows I will write matte5
‫0 colon 3
‫Comma
‫Colon
‫This means all the columns
‫If I run this I am getting
‫All the elements where the index is 0 1 or 2 remember 3 is excluded
‫So we are getting row with zero index row with one and row with 3 index
‫Since we are provided colon that means all the columns that's why we are getting all the columns.
‫There are arithmetic operations for numpy array also but we are not discussing it right now we'll move on to the pandas.