 So now that you've installed Python, we're going to open a notebook and I'm going to show you around. As a bonus, I'm going to show you how to construct your first matrices and how to access certain of the elements inside of a matrix. So here I am in a Jupyter notebook. This is a Windows system. So how did I open this? Well, I clicked on start. I scrolled down till I saw an Aconda 3. Open that and there we have Jupyter notebook. In macOS, please have a look at your applications folder to find the Jupyter notebook. And in Linux, you would open a terminal window and just type in Jupyter notebook. So we are here in the edge browser, which is my default on Windows. So once I open that, the browser opens and I see my folder structure. As if this was a normal folder viewer folder explorer. So I'm going to go down to my desktop. Click on that and I see I have two folders on my desktop. I want to create a new folder. So I'm going to just select new. Remember this was all in a browser and I'm going to go to folder. If I now go back to the desktop, I would see untitled folder. It might not jump back to the original page for you. In some instances, it does just navigate back to the desktop. I'm going to click on this little square here, which opens up the ability to rename that folder. So I'm going to rename that. And I'm going to type in linear algebra with some pi, symbolic python. Linear algebra with some pi and rename. It is there and when you look at your desktop, that folder will actually be there. So let's do that. Click on that and I'm inside of that folder now. We can see that it's empty. And what I want to do is create a new Python 3 file. You see I have Julia 0.6.2 as well there. That is because I install that separately. So we're going to go for Python 3 and we see a new tab opens up. It is untitled and here is our coding environment. Still was in within our browser. And we can see this little cell that we can start typing some code into. If we look above that though, this looks almost like a word processor because I have file, edit, view, insert, some of the normal things that we expect. And some buttons at the bottom, which are just shortcuts for some of these menu items. So if I click in that first cell, the most important thing to know is that there are different cell types. I can do different things inside of each of these cells. And that is what makes this notebook so beautiful and so powerful. If you go up here to this dropdown, you will note that you have code, markdown, raw nbconvert and heading. So there are four different types of cells. Let's convert the cell to markdown. Now markdown is like HTML, which is the language of webpages. But there's some shortcuts so that you don't have to type in all the HTML code. So imagine I want to change this into a large heading, the largest heading that a web page can have, just in normal terms. I would use one hashtag that shift and three are my keyboard. And I'm just going to type in title. And I can run that cell by clicking on run. Or I can hold down shift and hit enter or shift and return. And we see that was executed. And we see title written in h1 form. That's the largest HTML title tag, h1. Let's click on the second one. I also want to change this to markdown. And this one I want slightly smaller. But instead of doing two, which will be slightly smaller, three even smaller, four even smaller, and you can go down to six. Let's just use normal HTML in case you are familiar with that. So that will be heading two. And I close my square bracket. And I'm going to type in subtitle and close h2. If I now hold down shift and enter or shift and return, I see it's size two heading h2. It's slightly smaller. So instead of two hashtags, I can just use normal HTML. The one thing I want to show you is a comment line. So let's leave this third cell as code, which is the default. And I'm going to put one hashtag. So this is not HTML or markup. Any kind of markdown, markup, HTML, nothing like that. This is actual Python code, but it is a comment line. So I'm going to say this is a comment. And when I execute this shift and enter shift and return, nothing happens. But I can see in there, which I didn't see up there, because this is a cell that contains actual code. But if you start a line of code with a hashtag, Python will ignore that line. That is where you leave comments to yourself. Should you come back to the code in future? Or you give this file to someone else to have a look at and they want to know, why did you write this code? What's happening here? If you leave them some comments, that will help a lot. So let's click in this new cell. I'm going to comment it and I'm saying all I want to do is adding one and one. So I want to do one plus one. And that's very simple. I'm going to type one. Now you don't have to put spaces, but I put spaces in between things because it just looks a bit neater. So one plus one with the spaces in between. Again, I can just run it by clicking there or hold down shift and enter, shift return. And look at that. Now I suddenly have an output because there was a line of code that Python could execute one plus one is two. And indeed we saw, we know that it's two and we see a two right there. Let's change this into markdown as well. Click back in it. And I'm going to use two hashtags because that's shorter. Put my space and I'm going to say importing the Sympy library. Shift and enter, shift and return. And we see it's the same size as the subtitle. Because Python is a language, all on its own. There are extensions to that language though and we can import those extensions into Python so that we can use them as well. And that's the beauty of Anaconda because when you download it and install the Anaconda it put a huge number of packages right there for you and one go you don't have to worry about it. So let's comment this cell and I'm going to say import Sympy and I'm going to use and use an abbreviation. I'm going to use an abbreviation as well. And the way that we do the import is a very simple line of code. Import Sympy as let's use SYM. I'm just going to use SYM for now because it looks easy. So instead of having to type Sympy every time I'm using this abbreviation for this import. And lo and behold took a fraction of a second and the whole of Sympy was imported. So I've expanded the base of Python now to also include Sympy. But to use some of Sympy I have to reference Sympy and I use that through the abbreviation. Let's take a look at how that might work. Now instead of going all the way up hitting code and then markdown there's a bit of a shortcut. I can hit escape and you see that it turns from green to blue here. I'm going to hit the M key and I'm going to hit enter or return and I'm back to green and you see it is now a markdown. So that's a keyboard shortcut. Escape M enter or return and now it is marked down. Again I'm going to make it size two title and I'm going to say enabling enabling LaTeX printing. Because what I want to do and the reason why I'm using Sympy or symbolic Python I want to see nicely formatted mathematical printouts to the screen. I don't want to see the normal computer printouts I want to see beautiful mathematics as I would read it in a textbook. So I'm going to hold down shift and hit enter return and I see that was a nice size two heading and I'm going to say using init printing or enabling at least init printing. There we go. So init printing is a function inside of this extension Python so I have to reference I have to tell inside of Sympy so I have to tell the notebook here that please go look inside Sympy and get this init printing for me. Init printing and I'm going to put these parentheses shift a nine on my keyboard. So init printing is this function that lives inside of Sympy. I have to reference Sympy and I'm using the SYM because that was the abbreviation and I have to pass this function a few arguments. So that's how most computer languages work. I have a function and I have to tell that I have to give that function a few things so that that function can actually do something useful and those things that I give it are arguments and I pass these arguments to the function by typing them inside of in the case of Python these parentheses. If I hold down shift and hit tab I can actually see a bit of the code of all of these possible arguments that I could pass come up as a little tool tip so I can really quickly learn what arguments I can pass to a function by the fact that if I'm inside of these parentheses I hit shift and tab that brings all of them up and we'll go through how these things are constructed. The one that I'm interested in at the moment is this use LaTeX so I'm going to say use LaTeX and I'm just going to start typing and if I hit tab I see this auto completion so that's very useful that you don't have to type in anything always in Python inside of the notebook here type the first few letters and hit tab and it'll bring an option of all the possible things that start with those letters and you can select one of them and if there's just one well just hit tab and it'll auto complete for you there and inside of quotation marks I'm going to say math jacks and that would be a way for LaTeX printing to be enabled shift enter shift return and now I have some form of very nice printing to the screen so for now let's hit escape m enter and that changes our next cell to markdown and I'm just going to leave a comment to myself I'm going to leave or let's write that let's write using the matrix function so using the matrix function there we go let me leave a comment to myself let's say creating a two by two matrix so how would I create a two by two matrix once again I've got a reference some pie and inside of some pie there is this function called matrix with an uppercase m again I've got to pass it some arguments so I put my parentheses and each row of a matrix has to be put in separately and the whole thing has to go inside of square brackets so I'm going to hit my open square bracket just as with all the other parentheses quotation marks some Python at least will automatically put the closing square bracket there for you so again square bracket because that would be my first row and in my first row I want three and four I'm going to write a row to get out of that set of square brackets comma space and then my new set of square brackets and let's make that five and seven so note that there are two sets of square brackets inside of a larger set of square brackets and these are all arguments so there you go inside of parentheses and let's just hit shift and enter shift and return and look at that beautiful printing to the screen this is what this LaTeX printing does by using this init printing function and it prints this beautiful matrix to the screen and I see my first row there containing the elements three and four and my second one containing the elements five and seven so very beautiful there a very beautiful way to construct matrices let's make another markdown escape m enter return and again I'm going to make this of size two and I'm going to look at some of the inbuilt matrices the inbuilt matrices that are built into SMPI now the first one is the identity matrix so I'm going to leave a little comment to myself identity matrix there we go and that is very simple once again it lives inside of SMPI so I've got a reference SMPI so I'm going to say sim dot e y e i and then once again if I do my little parentheses I can do shift tab and it gives me this time not so many helpful tips there but what I do know is that it just wants the size of this and remember identity matrices are n by n so I just have to put in the value of n and let's make this identity matrix a three by three matrix so I'm just going to say s y m dot i three shift and enter and there is an identity matrix remember this ones on the main diagonal and zeros everywhere else so that's a three by three identity matrix let's make a matrix of all zeros so I'm going to say all say all zeros and let's make that also a three by three matrix so that would be simple it's s y m dot zeros and once again I'm going to put in three and I have a matrix that is of size square matrix of size three by three and everything is zeros let's do all ones and let's make this a four by four matrix and I think you've guessed it by now so it's s y m dot ones and with the argument four and I have a four by four square matrix and all the entries are just one the last one of these inbuilt functions I want to show you is the diagonal matrix so let's do a diagonal matrix and I have to tell it what all the values on the main diagonal are going to be s y m dot dy for diagonal and let's put in three and four and five and two notice that I just pass this as these arguments and I separate them with commas note that there are no sets of extra square brackets or anything like that and there we go a diagonal matrix only has values along the main diagonal and everything else is zero so that is a diagonal matrix the next thing I want to show you in this lesson is just how to save a matrix object inside of a computer variable so let's hit escape and enter or return and I'm going to do my usual two little hashtags there pound signs whatever you want to call them and then space to indicate again this is a second heading and I'm going to say saving a matrix object in a computer variable there we go so what I want to do is I'm going to create a four by four matrix and I'm going to save them inside of a computer variable so let's leave a little comment to ourselves I'm going to say creating the computer variable a I'm going to call it that holds a four by four matrix and I'm going to use another line of comment I'm going to use a semicolon I'm going to show you what that does a semicolon suppresses screen output it suppresses screen output so I'm going to say a equals and now I'm going to do my matrix sym dot matrix and I'm going to construct my four by four matrix now I've already typed it in here so just to save me from having to do all this typing I'm going to copy and paste it in and you have to type it in but just about saving a bit of time so I see I have four columns and those are each of the rows and those rows go inside of their own little set of square brackets I put a semicolon after that and if I shift and enter shift and return nothing happens I have suppressed output to the screen with that semicolon what have I done here though I've created a matrix but instead of having to retype it every time I want to use it I'm going to store it inside of what is called a computer variable and that is just a bit of space in your computer's memory it's given a name and it holds an object and that object is of a certain type and in our instance here that type is a Sympy matrix now if I want to bring it back to the screen I want to recall it so I'm just going to put a little comment to myself recalling recalling A and just A that's all I have to do now and if I do that there is my four by four matrix I don't have to retype it every time I want to use it it is now saved as a computer variable and that computer variable has a name and it's given by me I chose that and you can choose your own there are some rules and regulations about what you can and cannot do but most of the time if you just use a single word something descriptive and of course with matrices in a textbook you'll usually see an uppercase letter and for instance A and I've used A there so I've created this little space in my memory it holds an object and that object has a type and that type is a Sympy matrix let me show you I can use the Python function type now that already exists inside of Python it's not part of Sympy so I don't have to reference its library or its package name so I can just say type and I pass A to it and it says that it's a Sympy matrix dense mutable dense matrix and if you know anything about matrices you'll know we get dense matrices that is where you know most of the values are actually not zero and we get sparse matrices usually when they are huge most of the elements are zero here and there's a spattering of an actual value and that will be very memory inefficient to store such a big matrix so we just store the size of it and the address of the elements that are not zero and automatically all the other zeros are filled in so that would be a sparse matrix yeah everything has values so Python decided this will be a dense matrix mutable mutable means I can later go and change some of the values if I want it is not a fixed thing I can decide that I want to change one or two of the elements later it is a matrix as we can see there and it is part of a Sympy object so I had to use Sympy to generate this object let's go on I'm going to say escape m enter and I want to do another title and I'm going to say accessing accessing elements of a matrix using addressing there we go and I want to get to certain values now this is only a four by four matrix but imagine it was huge and I just want to reference some of the values or range of some of the values so I want to slice up in other words this matrix and the reason why I want to bring this in into lesson one is we've got to understand and come to grips with the fact that Python starts counting at zero so what we would see as row one column one Python is going to see as row zero and column zero and that is something to get used to so let's leave a little comment to ourselves and we're going to say the element the element in row one column one and that is a one so I'm going to reference it and the way to reference it is by not using parentheses but square brackets so I'm going to say a zero comma zero because one comma one row one column one for pythons actually row zero column zero so if I do that I see I get the value one back so let's play with us a bit let's say the element the element in row three and column two so because Python starts counting and zero I might as well say a and what I want for row three that would be three minus one because it's actually two and two minus one so that is going to give me row three there's row one two three column one two there's the six so it's exactly the same as saying two comma one because it started counting at zero so please please remember that let's carry on let's do the elements in row one so I'm going to say all the elements in row one that's all I want printed to the screen so again a and I'm going to put my square brackets and I'm going to say row one because it's always a row comma column so row one which is actually zero and then all the columns so column zero one two and three another little thing that's a bit awkward that you have to come become used to I can't now say zero to three zero to three would mean zero one two and three by putting this colon in between that's a nice way to compact your code so I don't have to say zero and one and two and three I put this colon in between so it says zero to three but what Python does in these instances it leaves out the last value so it'll actually only be zero one and two and that's only three columns I want all four columns unfortunately I have to reference five columns here because it's zero one two three four that means five but there's only four columns but as I said this last four it's not counted it counts up to but not including the last value so zero colon four actually means zero one two three very awkward but that's the way it is and if I do that I see all the elements in the first row so all row only row zero which is actually row one and zero to three which is actually written zero to four so just a little bit of getting used to now there's an alternative shortcut I'm going to say row zero and instead of zero to four because I might not know how many columns they are I'm just going to use the shortcut which is just the colon all on its own and to Python at least here in Simpy it means just do all of them irrespective of how many they are so I don't have to remember zero to 27 if they are 28 27 I should say so you don't have to go that you don't have to type in all of those you can just use this little shortcut now let's have a look at what the following will do I'm not going to leave a comment I'm going to type it in and you're going to guess what it's going to happen I'm going to say one colon four comma two colon four so let's see what's going to happen here it's going to be row comma column so let's look at the rows which is one column colon four so it's going to start at one and it's not going to include that four so it's going to be one two and three but remember that's not a row one two and three it starts counting at zero and the same goes for two to four as far as the columns that's two and three only but that's not the real column two and three let's have a look so there we go if we scroll back up and we look at where two one three is there's two one three and then we have negative two one and one so negative two one and one so what it did for us was rows two three and four two three and four for columns three and four and you see that subtraction by one because it started counting at zero so it is just something that you will have to become used to now what if I don't want a contiguous set of columns or rows so I don't want two three and four and the way that I would do that is let's just say all the rows please comma and let's do the list of columns and those I put inside of parentheses so let's say one comma three and so that will be two and four an actual fact and now I have all the rows for columns two and columns four which would obviously be in Python be one and three so I'm skipping that it's not one two and if I had to put and if I had to put a four there with one colon four that would be one two and three it's just one and three that I want so please get used to this referencing and starting counting at zero it just takes a little bit of getting used to if you look at this code again once you've used it a couple of times it becomes very easy to slice a matrix so that would be nothing be the normal stuff that you would look at when you start linear algebra but it is kind of the normal thing to look at when you look at writing computer code to do this is becoming used to the language so this was more back becoming used to the language than actual bit of linear algebra but there you go you can construct the matrix you can save it as a computer variable and now we can start using it in linear algebra and that will come up in the next lesson