﻿1
00:00:01,280 --> 00:00:03,584
‫So in this lecture we'll cover

2
00:00:03,840 --> 00:00:08,192
‫Important libraries of python which is numpy ,Pandas,

3
00:00:08,448 --> 00:00:09,472
‫Seaborn

4
00:00:10,240 --> 00:00:11,008
‫So here we'll

5
00:00:11,264 --> 00:00:13,824
‫Open our Jupiter home screen

6
00:00:14,080 --> 00:00:16,896
‫Click on new Python 3 notebook.

7
00:00:20,992 --> 00:00:24,064
‫First we'll cover the numpy

8
00:00:24,576 --> 00:00:28,416
‫Numpy is the code numerical computing package in Python

9
00:00:28,672 --> 00:00:31,232
‫And its code type is ######

10
00:00:31,488 --> 00:00:36,096
‫Also known as numpy array.

11
00:00:37,632 --> 00:00:39,680
‫You can change the title of notebook

12
00:00:48,128 --> 00:00:49,408
‫And save this

13
00:00:50,176 --> 00:00:54,016
‫Is also an autosave feature in jupyter Notebook

14
00:00:54,528 --> 00:00:56,832
‫So you don't have to worry about saving it.

15
00:00:58,624 --> 00:01:03,488
‫Numpy package is almost used in all numerical computation using python

16
00:01:04,000 --> 00:01:10,144
‫And it provides high performance vector Matrix and higher dimensional data structures for python

17
00:01:10,656 --> 00:01:13,728
‫It is implemented in C and FORTRAN

18
00:01:13,984 --> 00:01:18,848
‫And that's why it is much faster than Python inbuilt function.

19
00:01:19,616 --> 00:01:22,688
‫To use numpy we need to import the module

20
00:01:22,944 --> 00:01:29,088
‫Import the module will write import numpy

21
00:01:29,344 --> 00:01:31,136
‫Snp

22
00:01:31,904 --> 00:01:38,048
‫Since we are using Anaconda there is no need to install this library

23
00:01:38,304 --> 00:01:42,912
‫All the important libraries are already installed using the Anaconda.

24
00:01:43,424 --> 00:01:48,032
‫And if you are using Python you have to use PIP install in the command prompt

25
00:01:48,288 --> 00:01:49,824
‫Install this library.

26
00:01:52,640 --> 00:01:56,480
‫There are various ways to initialize a numpy array

27
00:01:57,760 --> 00:02:03,904
‫We can either convert existing Python list or tuple or we can generate a numpy array

28
00:02:04,160 --> 00:02:07,232
‫Using functions like a range and line space.

29
00:02:08,000 --> 00:02:10,304
‫So let's start with numpy array

30
00:02:11,328 --> 00:02:16,192
‫Will create a variable n p 1 equal to

31
00:02:16,704 --> 00:02:20,544
‫Np.array is a function

32
00:02:20,800 --> 00:02:25,152
‫This function of numpy package that's why we have to write n p

33
00:02:25,408 --> 00:02:27,968
‫So in the first statement we'll

34
00:02:28,480 --> 00:02:34,624
‫Install numpy as NP that's why we have to write  NP before every function of this numpy

35
00:02:34,880 --> 00:02:38,464
‫Package that's why I will write NP.array

36
00:02:39,744 --> 00:02:42,816
‫And then in the bracket will input a list

37
00:02:43,072 --> 00:02:45,376
‫As you remember list are

38
00:02:45,632 --> 00:02:51,264
‫Covered by square bracket square bracket we'll write a list 1, 2, 3, 4

39
00:02:53,056 --> 00:02:54,336
‫we enter

40
00:02:55,360 --> 00:02:56,640
‫If we write NP

41
00:02:57,152 --> 00:02:58,688
‫and run this

42
00:02:59,200 --> 00:03:00,480
‫You can see

43
00:03:00,992 --> 00:03:03,296
‫The output is showing us array

44
00:03:03,808 --> 00:03:06,880
‫Which contain element 1 2 3 and 4

45
00:03:08,160 --> 00:03:14,304
‫If we write type of NP one will give us

46
00:03:14,560 --> 00:03:17,120
‫Output that it is a numpy ND array.

47
00:03:18,400 --> 00:03:19,680
‫To create a matrix

48
00:03:19,936 --> 00:03:22,240
‫You have to pass two list

49
00:03:22,752 --> 00:03:28,128
‫its a nested list in which there are two lists so we'll write

50
00:03:29,664 --> 00:03:35,808
‫Mate1 equal to NP array .array

51
00:03:36,064 --> 00:03:37,600
‫Parenthesis will write

52
00:03:38,624 --> 00:03:41,184
‫nested list which contain two lists.

53
00:03:49,888 --> 00:03:50,912
‫If you run this

54
00:03:52,960 --> 00:03:54,496
‫We'll get a matrix.

55
00:03:56,032 --> 00:04:02,176
‫You can see this is a array in which our first floor is this which contains element for 1 and 2 and

56
00:04:02,432 --> 00:04:05,248
‫Second row is 3, 4.

57
00:04:06,784 --> 00:04:12,928
‫Our np1 is an one dimensional array where is ###### one is a two dimensional array

58
00:04:13,952 --> 00:04:18,047
‫Look at the shape of these two arrays will write

59
00:04:18,815 --> 00:04:20,607
‫Mp1.shape

60
00:04:21,119 --> 00:04:25,727
‫Dot shape is a Keyword that will give us the shape of that array.

61
00:04:26,239 --> 00:04:32,383
‫So np1 is our single dimensional array which contains only four elements if we write mate1.shape

62
00:04:39,295 --> 00:04:44,159
‫So you can see that this is a matrix which contain two rows and two columns.

63
00:04:46,719 --> 00:04:52,863
‫Unlike Python list in which you can combine multiple types of element in numpy array

64
00:04:53,119 --> 00:04:56,703
‫You have to insert only similar types of element.

65
00:04:58,239 --> 00:05:02,847
‫Get the type of elements of numpy Array you have to write

66
00:05:03,103 --> 00:05:04,639
‫D type so

67
00:05:04,895 --> 00:05:08,735
‫I write mat 1.Dtype.

68
00:05:11,039 --> 00:05:12,831
‫It will give me the

69
00:05:13,087 --> 00:05:17,183
‫Type of data elements in mat one array

70
00:05:17,951 --> 00:05:18,975
‫You can see

71
00:05:20,767 --> 00:05:22,815
‫The elements are integer

72
00:05:25,631 --> 00:05:27,935
‫I can change the value of element

73
00:05:28,191 --> 00:05:31,775
‫By just using equal to operator so if I write matte one

74
00:05:35,103 --> 00:05:39,455
‫Square bracket so my first element is 0, 0

75
00:05:40,223 --> 00:05:41,759
‫I write 0,0

76
00:05:42,271 --> 00:05:45,855
‫Equal to 5

77
00:05:46,111 --> 00:05:48,159
‫It will assign the first element

78
00:05:48,415 --> 00:05:49,951
‫Value 5

79
00:05:50,207 --> 00:05:56,095
‫Output you can see that first element is now changed to 5 instead of 1 earlier

80
00:05:57,887 --> 00:06:03,263
‫If I try to assign some string value to this array will get an error because

81
00:06:03,519 --> 00:06:04,799
‫As I said earlier

82
00:06:05,055 --> 00:06:09,151
‫All the elements of numpy Array should be of same type.

83
00:06:10,431 --> 00:06:16,575
‫You can see you are getting an error because all the other element are of type integer and we cannot

84
00:06:16,831 --> 00:06:17,343
‫pass

85
00:06:17,855 --> 00:06:18,623
‫A string

86
00:06:18,879 --> 00:06:22,463
‫Element into this numpy array that's why we are getting an error.

87
00:06:23,999 --> 00:06:25,023
‫In list

88
00:06:25,791 --> 00:06:27,839
‫We use the function range

89
00:06:28,095 --> 00:06:29,119
‫to generate

90
00:06:29,375 --> 00:06:30,911
‫Numbers in a sequence.

91
00:06:31,679 --> 00:06:32,703
‫Numpy array

92
00:06:33,471 --> 00:06:35,775
‫We can use function arrange

93
00:06:36,543 --> 00:06:40,127
‫Similarly to generate elements for example

94
00:06:41,919 --> 00:06:42,687
‫If I want

95
00:06:42,943 --> 00:06:45,247
‫New variable Matte 2 equal to

96
00:06:45,503 --> 00:06:51,647
‫Now I want it to start from 0 to 10 with a step of 1 I write  Np

97
00:06:51,903 --> 00:06:53,695
‫Dot a range

98
00:06:58,815 --> 00:07:01,375
‫And then the start point Which is zero

99
00:07:01,631 --> 00:07:03,679
‫, the end point which is

100
00:07:03,935 --> 00:07:04,703
‫10

101
00:07:04,959 --> 00:07:06,751
‫Comma ####### which is one

102
00:07:08,799 --> 00:07:09,823
‫I run this

103
00:07:12,383 --> 00:07:13,407
‫You can see that

104
00:07:13,663 --> 00:07:15,199
‫NoW MATTE2 contains

105
00:07:15,455 --> 00:07:18,271
‫All the values from 0 to 9

106
00:07:18,783 --> 00:07:21,087
‫Stopping point is excluded

107
00:07:21,343 --> 00:07:23,391
‫but the starting point is included.

108
00:07:24,671 --> 00:07:30,047
‫Similarly we want to include both the elements both the starting point and stopping point

109
00:07:30,303 --> 00:07:32,607
‫We have to use linspace function.

110
00:07:33,119 --> 00:07:37,215
‫Will write matte3 equal to

111
00:07:37,471 --> 00:07:39,007
‫Np.#######

112
00:07:45,919 --> 00:07:52,063
‫our starting point is zero our ending point is 10 and here instead of steps

113
00:07:52,319 --> 00:07:58,463
‫You have to mention the number of elements we want so if you want 20 elements we have to write 20.

114
00:07:59,487 --> 00:08:01,535
‫if we see

115
00:08:02,559 --> 00:08:07,679
‫We have 20 elements filled between our starting point and ending point.

116
00:08:08,447 --> 00:08:12,543
‫Here the array is coming in the form of matrix

117
00:08:13,055 --> 00:08:18,431
‫But if we find out the shape of this you can see that this is only a one dimensional array.

118
00:08:18,687 --> 00:08:22,783
‫Can see there are 20 elements and this one dimensional array.

119
00:08:26,367 --> 00:08:28,415
‫Now to generate a random matrix

120
00:08:29,183 --> 00:08:31,487
‫You can do that by using NP dot

121
00:08:32,511 --> 00:08:34,303
‫Random

122
00:08:35,071 --> 00:08:38,655
‫.trend

123
00:08:41,471 --> 00:08:45,567
‫Here we have to specify the number of columns ,number of rows

124
00:08:45,823 --> 00:08:50,431
‫Example if we want five rows and five columns we can write 5,5

125
00:08:50,943 --> 00:08:53,503
‫To Do this

126
00:08:54,015 --> 00:08:56,575
‫we'll view our Matrix 4

127
00:08:57,855 --> 00:09:00,671
‫It contain random number between 0 and 1

128
00:09:01,183 --> 00:09:03,231
‫And this is a 5 by 5 matrix.

129
00:09:04,511 --> 00:09:07,071
‫Now if you want a normally distributed

130
00:09:07,327 --> 00:09:08,351
‫Random numbers

131
00:09:13,471 --> 00:09:17,823
‫Can do this by changing

132
00:09:18,335 --> 00:09:21,151
‫Random.#######

133
00:09:21,407 --> 00:09:26,527
‫Again 5,5

134
00:09:34,975 --> 00:09:41,119
‫There are other functions as well to create metrics such as NP diag

135
00:09:41,375 --> 00:09:47,007
‫Create a diagonal Matrix in which only the element of the diagonal have the value

136
00:09:47,263 --> 00:09:53,151
‫Mp.0 will create empty Matrix in which all the elements are zero

137
00:09:53,407 --> 00:09:58,271
‫Np dot one will create a matrix in which all the elements have value 1

138
00:09:58,783 --> 00:10:03,135
‫You are not discussing this right now but you can explode this on your own.

139
00:10:15,423 --> 00:10:21,567
‫Now just like in a list or Strings we can also use slicing using the index now

140
00:10:21,823 --> 00:10:22,335
‫Number

141
00:10:22,847 --> 00:10:25,151
‫So for example if we write

142
00:10:25,663 --> 00:10:26,687
‫Matte 5

143
00:10:29,247 --> 00:10:30,527
‫0, 0

144
00:10:34,367 --> 00:10:37,439
‫It will give me the first element of this Matrix 5

145
00:10:37,951 --> 00:10:38,719
‫if I write

146
00:10:38,975 --> 00:10:41,023
‫matte 5

147
00:10:42,303 --> 00:10:44,351
‫0, 1

148
00:10:47,423 --> 00:10:51,775
‫It will give me the element from the First row that is the zeros

149
00:10:52,031 --> 00:10:58,175
‫with index 0 and the second column that is the column with index one I am getting this value

150
00:10:58,431 --> 00:10:59,711
‫as a output.

151
00:10:59,967 --> 00:11:05,599
‫If I want to select all this value that means all the values from

152
00:11:06,111 --> 00:11:09,183
‫First 3 rows I will write matte5

153
00:11:14,559 --> 00:11:16,095
‫0 colon 3

154
00:11:19,423 --> 00:11:20,447
‫Comma

155
00:11:21,727 --> 00:11:22,239
‫Colon

156
00:11:22,751 --> 00:11:25,311
‫This means all the columns

157
00:11:25,823 --> 00:11:27,871
‫If I run this I am getting

158
00:11:28,127 --> 00:11:33,503
‫All the elements where the index is 0 1 or 2 remember 3 is excluded

159
00:11:33,759 --> 00:11:39,903
‫So we are getting row with zero index row with one and row with 3 index

160
00:11:40,159 --> 00:11:44,767
‫Since we are provided colon that means all the columns that's why we are getting all the columns.

161
00:11:45,791 --> 00:11:49,375
‫There are arithmetic operations for numpy array also but we are not discussing it right now we'll move on to the pandas.

