0:02 we can create numpy arrays with more
0:05 than one dimension this section will
0:07 focus only on 2d arrays but you can use
0:10 numpy to build arrays of much higher
0:13 dimensions in this video we will cover
0:16 the basics and array creation in 2d
0:19 indexing and slicing in 2d and basic
0:24 operations in 2d consider the list a the
0:26 list contains three nested lists each of
0:29 equal size each list is color-coded for
0:32 simplicity we can cast the list to a
0:35 numpy array as follows it is helpful to
0:36 visualize the numpy array as a
0:39 rectangular array each nested list
0:41 corresponds to a different row of the
0:44 matrix we can use the attribute and dim
0:47 to obtain the number of axes or
0:50 dimensions referred to as the rank the
0:52 term rank does not refer to the number
0:54 of linearly independent columns like a
0:57 matrix it's useful to think of n dim as
0:59 the number of nested lists the first
1:02 list represents the first dimension this
1:05 list contains another set of lists this
1:07 represents the second dimension or axis
1:10 the number of lists the list contains
1:12 does not have to do with the dimension
1:15 but the shape of the list as with the 1d
1:18 array the attribute shape returns a
1:19 tuple it's helpful to use the
1:22 rectangular representation as well the
1:24 first element in the tuple corresponds
1:26 the number of nested lists contain in
1:29 the original list or the number of rows
1:31 in the rectangular representation in
1:34 this case 3 the second element
1:36 corresponds to the size of each of the
1:38 nested lists or the number of columns in
1:41 the rectangular array 0 the convention
1:45 is to label this axis 0 and this axis 1
1:48 as follows we can also use the attribute
1:51 size to get the size of the array we see
1:54 there are three rows and three columns
1:56 multiplying the number of columns and
1:58 rows together we get the total number of
2:02 elements in this case 9 check out the
2:04 labs for arrays of different shapes and
2:06 other attributes we can use rectangular
2:08 brackets to access the different
2:10 elements of the array the following
2:12 image demonstrates the relationship
2:13 between the indexing
2:15 inventions for the list like
2:17 representation the index in the first
2:19 bracket corresponds to the different
2:22 nested lists each a different color the
2:24 second bracket corresponds to the index
2:26 of a particular element within the
2:28 nested list using the rectangular
2:31 representation the first index
2:34 corresponds to the row index the second
2:37 index corresponds to the column index we
2:40 can also use a single bracket to access
2:41 the elements as follows
2:45 consider the following syntax this index
2:47 corresponds to the second row and this
2:51 index the third column the value is 23
2:54 consider this example this index
2:56 corresponds to the first row and the
2:58 second index corresponds to the first
3:03 column and a value of 11 we can also use
3:06 slicing in numpy arrays the first index
3:08 corresponds to the first row the second
3:11 index accesses the first two columns
3:14 consider this example the first index
3:17 corresponds to the last two rows the
3:21 second index accesses the last column we
3:23 can also add arrays the process is
3:26 identical to matrix addition consider
3:28 the matrix X each element is colored
3:30 differently consider the matrix Y
3:33 similarly each element is colored
3:36 differently we can add the matrices this
3:38 corresponds to adding the elements in
3:40 the same position ie adding elements
3:42 contained in the same color boxes
3:45 together the result is a new matrix that
3:48 is the same size as matrix Y or X each
3:50 element in this new matrix is the sum of
3:53 the corresponding elements in x and y to
3:56 add two arrays in numpy we define the
3:58 array in this case X then we define the
4:02 second array Y we add the arrays the
4:04 result is identical to matrix addition
4:07 multiplying an umpire array by a scalar
4:09 is identical to multiplying a matrix by
4:13 a scalar consider the matrix Y if we
4:15 multiply the matrix by the scalar two we
4:17 simply multiply every element in the
4:20 matrix by two the result is a new matrix
4:22 of the same size where each element is
4:25 multiplied by to consider the array Y we
4:27 first define the array
4:29 we multiply the array by a scaler as
4:31 follows and assign it to the variable Z
4:34 the result is a new array where each
4:36 element is multiplied by two
4:38 multiplication of two arrays corresponds
4:41 to an element-wise product or Hadamard
4:44 product consider array X and array Y
4:46 Hadamard product corresponds to
4:48 multiplying each of the elements in the
4:51 same position i.e multiplying elements
4:52 contained in the same color boxes
4:55 together the result is a new matrix that
4:58 is the same size as matrix Y or X each
5:01 element in this new matrix is the
5:03 product of the corresponding elements in
5:07 x and y consider the array x and y we
5:09 can find the products of two arrays x
5:11 and y in one line and assign it to the
5:14 variable Z as follows the result is
5:17 identical to how to Mart product we can
5:19 also perform matrix multiplication with
5:22 numpy arrays matrix multiplication is a
5:25 little more complex but let's provide a
5:27 basic overview consider the matrix a
5:30 where each row is a different color also
5:33 consider the matrix B where each column
5:36 is a different color in linear algebra
5:39 before we multiply matrix a by matrix B
5:41 we must make sure that the number of
5:44 columns in matrix a in this case 3 is
5:46 equal to the number of rows in matrix B
5:50 in this case 3 for matrix multiplication
5:53 to obtain the if' Rho and J a column of
5:56 the new matrix we take the dot product
5:59 of the I row of a with the jf columns of
6:03 B for the first column first row we take
6:06 the dot product of the first row of a
6:08 with the first column of B as follows
6:12 the result is 0 for the first row in the
6:14 second column of the new matrix we take
6:17 the dot product of the first row of the
6:19 matrix a but this time we use the second
6:23 column of matrix B the result is 2 for
6:24 the second row and the first column of
6:27 the new matrix we take the dot product
6:29 of the second row of the matrix a with
6:32 the first column of matrix B the result
6:35 is 0 finally for the second row and the
6:38 second column of the new matrix we take
6:40 the dot product of the second row of the
6:41 matrix a
6:43 with the second column of matrix B the
6:46 result is two in numpy we can define the
6:49 numpy arrays a and B we can perform
6:51 matrix multiplication and assign it to
6:55 array C the result is the array C it
6:57 corresponds to the matrix multiplication
7:01 of array a and B there is a lot more you
7:04 can do with it in numpy check out numpy