Hang tight while we fetch the video data and transcripts. This only takes a moment.
Connecting to YouTube player…
Fetching transcript data…
We’ll display the transcript, summary, and all view options as soon as everything loads.
Next steps
Loading transcript tools…
17. Numpy 2D Arrays | Python Things | YouTubeToText
YouTube Transcript: 17. Numpy 2D Arrays
Skip watching entire videos - get the full transcript, search for keywords, and copy with one click.
Share:
Video Transcript
we can create numpy arrays with more
than one dimension this section will
focus only on 2d arrays but you can use
numpy to build arrays of much higher
dimensions in this video we will cover
the basics and array creation in 2d
indexing and slicing in 2d and basic
operations in 2d consider the list a the
list contains three nested lists each of
equal size each list is color-coded for
simplicity we can cast the list to a
numpy array as follows it is helpful to
visualize the numpy array as a
rectangular array each nested list
corresponds to a different row of the
matrix we can use the attribute and dim
to obtain the number of axes or
dimensions referred to as the rank the
term rank does not refer to the number
of linearly independent columns like a
matrix it's useful to think of n dim as
the number of nested lists the first
list represents the first dimension this
list contains another set of lists this
represents the second dimension or axis
the number of lists the list contains
does not have to do with the dimension
but the shape of the list as with the 1d
array the attribute shape returns a
tuple it's helpful to use the
rectangular representation as well the
first element in the tuple corresponds
the number of nested lists contain in
the original list or the number of rows
in the rectangular representation in
this case 3 the second element
corresponds to the size of each of the
nested lists or the number of columns in
the rectangular array 0 the convention
is to label this axis 0 and this axis 1
as follows we can also use the attribute
size to get the size of the array we see
there are three rows and three columns
multiplying the number of columns and
rows together we get the total number of
elements in this case 9 check out the
labs for arrays of different shapes and
other attributes we can use rectangular
brackets to access the different
elements of the array the following
image demonstrates the relationship
between the indexing
inventions for the list like
representation the index in the first
bracket corresponds to the different
nested lists each a different color the
second bracket corresponds to the index
of a particular element within the
nested list using the rectangular
representation the first index
corresponds to the row index the second
index corresponds to the column index we
can also use a single bracket to access
the elements as follows
consider the following syntax this index
corresponds to the second row and this
index the third column the value is 23
consider this example this index
corresponds to the first row and the
second index corresponds to the first
column and a value of 11 we can also use
slicing in numpy arrays the first index
corresponds to the first row the second
index accesses the first two columns
consider this example the first index
corresponds to the last two rows the
second index accesses the last column we
can also add arrays the process is
identical to matrix addition consider
the matrix X each element is colored
differently consider the matrix Y
similarly each element is colored
differently we can add the matrices this
corresponds to adding the elements in
the same position ie adding elements
contained in the same color boxes
together the result is a new matrix that
is the same size as matrix Y or X each
element in this new matrix is the sum of
the corresponding elements in x and y to
add two arrays in numpy we define the
array in this case X then we define the
second array Y we add the arrays the
result is identical to matrix addition
multiplying an umpire array by a scalar
is identical to multiplying a matrix by
a scalar consider the matrix Y if we
multiply the matrix by the scalar two we
simply multiply every element in the
matrix by two the result is a new matrix
of the same size where each element is
multiplied by to consider the array Y we
first define the array
we multiply the array by a scaler as
follows and assign it to the variable Z
the result is a new array where each
element is multiplied by two
multiplication of two arrays corresponds
to an element-wise product or Hadamard
product consider array X and array Y
Hadamard product corresponds to
multiplying each of the elements in the
same position i.e multiplying elements
contained in the same color boxes
together the result is a new matrix that
is the same size as matrix Y or X each
element in this new matrix is the
product of the corresponding elements in
x and y consider the array x and y we
can find the products of two arrays x
and y in one line and assign it to the
variable Z as follows the result is
identical to how to Mart product we can
also perform matrix multiplication with
numpy arrays matrix multiplication is a
little more complex but let's provide a
basic overview consider the matrix a
where each row is a different color also
consider the matrix B where each column
is a different color in linear algebra
before we multiply matrix a by matrix B
we must make sure that the number of
columns in matrix a in this case 3 is
equal to the number of rows in matrix B
in this case 3 for matrix multiplication
to obtain the if' Rho and J a column of
the new matrix we take the dot product
of the I row of a with the jf columns of
B for the first column first row we take
the dot product of the first row of a
with the first column of B as follows
the result is 0 for the first row in the
second column of the new matrix we take
the dot product of the first row of the
matrix a but this time we use the second
column of matrix B the result is 2 for
the second row and the first column of
the new matrix we take the dot product
of the second row of the matrix a with
the first column of matrix B the result
is 0 finally for the second row and the
second column of the new matrix we take
the dot product of the second row of the
matrix a
with the second column of matrix B the
result is two in numpy we can define the
numpy arrays a and B we can perform
matrix multiplication and assign it to
array C the result is the array C it
corresponds to the matrix multiplication
of array a and B there is a lot more you
can do with it in numpy check out numpy
Click on any text or timestamp to jump to that moment in the video
Share:
Most transcripts ready in under 5 seconds
One-Click Copy125+ LanguagesSearch ContentJump to Timestamps
Paste YouTube URL
Enter any YouTube video link to get the full transcript
Transcript Extraction Form
Most transcripts ready in under 5 seconds
Get Our Chrome Extension
Get transcripts instantly without leaving YouTube. Install our Chrome extension for one-click access to any video's transcript directly on the watch page.