hi and welcome back to our for
statistics and data science right last
time we talked about sub setting
matrices we used square brackets to
extract elements by row and column index
blank spaces to call all elements in a
dimension and we called elements by
column or row name in this lesson we
will talk about matrix arithmetic which
I expect will remind you a lot of doing
arithmetic with vectors it should be
nice and easy and quick alright matrices
are just vectors older brothers okay
this means that they share a lot of
their properties do you remember the
mechanics of vector operations well they
happen in element wise manner this holds
true for matrices - let's try scaling a
matrix first I will super quickly create
a matrix with the box office data for a
new movie franchise worth stepping away
from Harry Potter for a little bit a
matrix with the matrices grosses in the
US and worldwide
you
great we have a simple three by two
matrix telling us how the movies from
the matrix franchise fared on US soil
and worldwide that's it we're all set to
jump right into the calculations
notice that the figures in our matrix
are in millions in u.s. dollars well
what if I wanted to convert the millions
into billions for example because I have
other data I want to compare this to and
that data is in billions well in this
case I can use the scalar multiplication
scalar operations comprise multiplying
or dividing an entire structure by a
single number
in this case because I want the data in
billions I will divide my matrix by a
thousand and get the desired result like
this
see the operation happens element by
element just like it did the vectors
fantastic so what if I wanted to know
how much each movie made after we
subtract the money that went into
producing the movie of course the movies
had different budgets but their average
is 121 million dollars to find out the
margin for the Matrix movies we just
need to subtract a hundred and
twenty-one from the matrix mat and there
you have it
notice that the command was again
executed on element by element basis
okay so this holds true for all
arithmetic operations
all right but what about the more
interesting stuff like matrix by matrix
arithmetic
well those are also governed by the same
rules everything will happen element
wise
for example if we take the margin
calculation we did before but this time
decided to use the real budgets for each
movie instead of their average we can
create another 2x3 matrix with the
information and subtract it from matrix
dot map like this
you
and as before the operation is happening
cell by cell
okay so did you notice how we made the
budget matrix just now we passed three
values one for each row and asked to
create two columns because the vector we
passed was only of length three and we
are asking are for a matrix that has six
values or is three by two are recycled
the vector and created it for us
repeating the three values twice
to be very honest we didn't need to do
that because our will recycle even if we
had simply subtracted a vector with the
values 63 150 and 150 from the Matrix
top map matrix let's try it out
yeah awesome the result we get is
identical with the one before because
our recognises the vector and the matrix
as being of different sizes and does
whatever it can to rectify this for the
operation at hand in other words it
recycles fantastic let's move on to
matrix multiplication if you have been
paying attention to everything we've
said so far it will be painfully obvious
to you that when you multiply two
matrices together the operations will
happen how element by element good let's
have a quick look I will multiply the
box-office gross for the franchise by a
three by two matrix
storing the numbers from 1 to 6
you
it works just like expected
if you are a linear algebra enthusiast
however you may be hoping that matrix
multiplication happens the way
traditional matrix multiplication is
supposed to happen if this is what
you're after you just have to ask nicely
in their multiplication happens when you
use this operator
and outer multiplication when you use
this one
don't forget to transpose though we did
this with the T function remember of
course if you truly are a linear algebra
enthusiast that's probably the first
thing that came to mind didn't it okay I
will finish the lesson on this note and
next time we'll switch the focus a
little bit to more mathematically
inclined matrix operations like finding
column and row sums averaging and so on
for more videos like this one please
subscribe