 And here we presented with the iPython notebook. You'll see I'm using the Chrome browser here. And it starts off with a notebook there. And it's because I launched it while I was in my home directory. It's going to show that up. And this is just our normal folder structure on my computer. I'm going to go here to my desktop. And the healthcare research lecture is there. And there is one file in there. It's an iPyNB, an iPython file. An iPython notebook file I should say. I can delete it there, which I don't want to do. If I click on it, it's going to open. Before I do that though, I just want to show you this new notebook. So that is how we're going to create a new notebook. I think I'll repeat it later. Whenever you open a new notebook, that notebook is going to be saved in your hard drive in whichever folder you are in at the moment. So let's just click New Folder there, New Notebook. And this is what it looks like. I'm going to run through that again in a minute. You can click on there to go to the website. There's the name. We'll run through that. This is our toolbar up here. And normal things that you would see there. File, Edit, View. Normal things and some other weird ones. And the Save button again. Insert Cells, Cut and Copy and Paste. We can see moving cells up and down. And then more importantly, the plane of the cells and the type of cells. We'll get to that again. And this is the beauty of iPython. So this is a cell. This is where you're going to type your code. At the moment, the cell that is active is set to Code. But look, I can also set it to Markdown. Markdown, there's a special short-hand sort of computer code that you can write text with, but you can also use normal HTML tags. Now in this and it will render this code to this web page as if it is code written specifically for a web page. Shortcuts there. Heading 1, Heading 2. Remember from HTML, those would just be the size of the text. So in short, this is a notebook. But let's open the one that we really want to see when I've left it open there. So it says I can shut it down. The other way to shut it down would be first to save it. And then to save file, close and halt. Now when I go there, it's not open anymore. We can delete it. There's the delete button. So let's open introduction to the IPython notebook. Now immediately you'll see that it has changed its look. It doesn't look like the other one and that's because of this code. Now this code is going to run immediately. All these files look the same. It will say, setting up fancy, a fancy style sheet. You can do some CSS files. So don't worry, that's not part of the course. But you can write some style sheets, cascading style sheets. You can import that and that will render this webpage looking a bit different. So this is the render I've gone for and the design that I've gone for just for this course. So don't worry about this few lines of code. What I do want to show you, if I go into that first cell and double click to edit it, you'll see it is marked down and I can just type normal text in there. I didn't even use any HTML or markdown language. I just typed in that and if I run that, it is this normal HTML output to this webpage. Now in cell 2, we're going to run that. Don't worry about this code but to execute it, I'm in that cell and I just hit the play button and it executes. Now you're going to see this numbering down here. The first time that you run it, you're not going to see these numbers but it's going to start off always with number 1 and when you hit enter and that code is busy executing, there will be a little star there and then it turns to whatever number cell is. These are really not important files. The other thing that I'm always going to do at the top of these cells is just to set up my Python environment. I'm going to start looking a lot more complicated and we'll go through this for the moment. I'm just using this code, ignore that for now. All I want to do is run it. Remember here I press the play button. Here I'll do the other way of doing it. You hold down the shift key and then hit the return or enter key and that will also play that cell. So look at this cell. It's nice and fancy and big text. If I double click on it, you'll see it is, the cell is marked as H1, hitting 1 and my style sheet will render the type of text that I wanted there. So it's just a nice way to lay out your notebook if you wanted to hand this notebook over to someone else with some text encoding in. This is a lovely way to do it and that is why Ipython is so fantastic for scientific computing because you can really collaborate, send your notebooks to someone else. You can do it with normal text, intermix it with code. It's just fantastic. There's our citation there for Fernando Perez and the guys who developed Ipython and still actively developing it. I think you can't say enough about this Ipython notebook if it really is phenomenal what these guys have done and are doing. So this Ipython, it's not only the notebook that we're dealing with here if you use something like Anaconda to install your Python environment specifically on the Windows and Mac version you're going to get a launcher that also has the other two parts of the Ipython family and number one is just going to be a terminal window called the QT console and that just looks like a normal command prompt window or terminal window you can write your Ipython code there and there's also the scientific development environment called SPIDER that is also installed, we're not going to use that we make use of this notebook now you can learn a lot more just to show you this cell here, learning more I just typed the letters and I marked it as heading 2 and when I execute it by holding and shift hitting return or enter it renders beautifully as H2 text now you can learn a lot more from the Ipython website itself let's see how I constructed this cell P the tags P there that's normal HTML that's this paragraph close paragraph, you don't have to learn HTML code or markdown code but you'll pick it up just by double clicking on the cells and you'll quickly learn the basics of it HTML is really easy and this is these two star signs here which is shift 8 just on most keyboards that is just the shortcut for italics so anything between two stars and there's got to be no spaces there will output just as italics the other way to do it was just to use HTML tags that would be I and remember always to close your tags close I so anything between those tags would be italicized I know a website I just typed that normally Ipython changed that into a link for me so if I hit enter see the Ipython there is an italics now you can with the notebook also just have live websites so I've written some code don't worry about this code it's not part of the course but look there the source is this website and I'm showing it how big frame to allow inside of this page this is the live website and so you can even embed live websites you can embed youtube videos there's all sorts of code that you can write in python to do all of this for you no matter all I want you to do here is to visit that website you can obviously learn a lot more about Ipython so let's just quickly re-run through the essentials there's various ways to start Ipython one way is to use the launcher which installs with anaconda for the python version 3.4 and up on windows and mac on linux though you'll have to open a terminal window but even in windows you can open a command prompt window or linux or mac open a terminal window and you just type in Ipython notebook and you hit enter or return it's going to open your default browser in the folder that you are currently in when you ran this command in terminal window whatever folder you are in on your computer's hard disk it's going to open in late in your default browser as we saw before so with these modern versions of anaconda 3.4 you actually get this navigation you do get this navigation that did not always exist didn't exist before but you can so I showed you how to open the new new notebook and I also showed you the toolbar if you were to click look here I've just imported an image which lives in this very same folder so I can just refer to the file itself in the same folder that this notebook is in so this file is right in this folder it doesn't show up because it's not a notebook but because it lives in the same folder I can just reference it if it wasn't I would have to put in c colon forward slash forward slash for windows wherever it was hidden I had to write out the whole computer address for this but because they're in the same folder I can just do this and there's a beautiful image what I wanted to show you here is if you double click there in other words this is going to show up and you can rename or name your notebook there that name will then be saved and it will update there ok the cells we've spoken about that is really the beauty of of iPython if I double click on there there's that code see all the p's close p open p, close p, open p, close p so this is all going to be rendered as paragraphs between each of these p's and close p's that will render as a paragraph and then start a new paragraph there and remember the little star signs yes those were just for italicizing and you can see the cell is marked on italicizing that text so if I run it 1, 2, 3 paragraphs and we've got the italics there nbconvert we'll talk about that a little bit later there is a way then in the terminal or command prompt window that you can use iPython, space nbconvert and then the name of your file and that will convert it to another format so you can do html you can do pdf and we'll do a bit of that later on and that's a beautiful way to save these notebooks in a different format than the iPyNB format you can save it as html or pdf as I mentioned and you can share it with someone else let's start coding a bit now usually with learning computer language people start with a hello world example I'd like to start with some mathematics though now one of the basic building blocks basic building blocks of any computer language is the variable now I use the term computer variable because I also do a lot of lectures in maths and obviously a mathematical variable is something other than a computer variable so what's a computer variable well in essence it is this space in a computer's memory we can call it an empty bucket and that variable name is the name we give to that bucket and we can put various things into that bucket so let's try this out live so in this cell all I've done is I've written a equals 7 there's that little bit there a equals 7, a is my variable and it's name and so I've created this space in memory this bucket I've called it a and I've put a value into that 7 now the 7 is an integer and you'll see this pound sign hashtag sign whatever you want to call it anything in a line after this little sign is ignored by Python so it will not be executed so if you want to leave some notes for yourself like I've done here, a equals 7 the value 7 is an integer that just gets ignored, you see it's turned green here and in a new line I've started this new line look there with another hashtag sign ignored but it's just that if you hand this over to someone else or you review your code later on and you've put these little reminders these little comments you've left them there, it'll help you out tremendously so unlike other computer languages I don't have to tell Python what type of data I'm putting in here, this is an integer it'll just infer from context now let's just execute this, I'm going to hit shift enter and nothing happens nothing happens you see this is jump to number 3 just executing that nothing has happened, it's just created this little space in the computer's RAM in the memory, called it A that little space and it's put a value in it very exciting indeed now let's heat things up, let's go to this cell and I'm going to say B equals 4 hit shift enter, shift return or the play button in another bucket I've put another integer value into it now do I get to what's in that though I can just simply type A so that would be one way if I just type in A and I hit enter low and behold the 7 appears it remembers that 7 is that so I'm just going to output that so my input code there in the cell was A I hit shift enter, shift return and it did 7, another way to do it is to use the print command there's big difference between the python version's 2, 2.7 2.5, 2.6, 2.7 and the version 3.x 3, 3.1, 3.2, 3.4 as this is big difference with those you just had this print A like that it's not going to work if you run older code so this is for python version 3 and up so if I say print A and I run this low and behold we're also going to get the 7 now let's do some math what is 7 to the power 4 and this is the way you do powers in python it's this double star sign not like in most computer languages where you use this carrot you can use the double equal sign so I've written A now these spaces here you need to put spaces here we go it's just that in 2401 now we can do simple addition what would be remember I had 7 and 4 if I just typed in 7 plus A plus B I run that obviously that's going to give me an 11 A minus B is going to be 3A times B it's just a 1 star sign it's 28A divided by B 5.5 now where did we go 2.75 I'm just going to warn you as well with all the versions any number that you put in that's an integer is going to be seen purely as an integer actually in python version 3 or the version 3's it actually sees these values as floats and if you're using python 2.7 for instance you might get really strange things when you do division to just watch out for that this is the modulus sign 7 by 4 4 goes into 7 once and 3 is left that 3 is the modulus so that's what you're going to get there now you can also force the arithmetic operations the order of that so I want to add A plus B first and then divide it by 2 if I didn't use those it was going to do remember B divided by 2 and then add that to A so you can force it just by parentheses and now for the reason why I call these things computer variables because what's going to happen in this line of code A equals A plus 5 that makes no algebraic sense as you would well imagine because if I brought A to the other side it's going to say 0 equals 5 and that doesn't work because these are not algebraical mathematical variables these are computer variables so what does the computer say it executes the right hand side of this equation first it says what is an A at the moment well there's 7 in there 5 to that that makes a 12 and I'm going to put that 12 into that bucket which was called A ok so that's what's going to do and let me behold if I print that it's now 12, A is now 12 now for the real power of Python the beauty and power of Python we can extend the language by simply importing code someone else has developed for us and the way to import this is to use the import statement import math so math is this module sometimes we refer to these as libraries modules someone who's intimately familiar with Python and computer language will obviously know what the differences are for us we can just call it whatever we want import math so let's run that code so math is now part it's extended and it's little mind Python's mind it's extended all the code you can use by importing this math module now I'm going to use the sign of pi now I have to refer to this module or library first before I can use whatever's inside of it so I have to say math dot sign of math dot pi and that's not the way we're going to do it I'm just showing you how to reference code it's inside of a library so I have to use the library name and then whatever's inside of it so this math dot sign the sign will be a method inside of the math module there if I execute that you're going to see something very funny now remember pi has got an infinite number of decimal places it goes on forever your computer can't do that it's going to truncate it some way and then it's going to take the sign of that truncated value and it can do quite a fair bit with that but because it's not an exact thing that it doesn't go off to infinity you are going to get this scientific notation 1.2 times 10 to the power negative 16 well anything with 16 zeros after the decimal point you can obviously see python was trying to say that this is zero the sign of pi or the sign of 180 degrees is zero and another way to do or another way to import modules is to say from math import these methods that you want cosine, pi so it's only going to import those it's run that the beauty of that though is now I don't have to refer to that module name I don't have to say math dot cosine math dot pi I can just say the cosine of pi so what's the cosine of 180 degrees negative 1 so that's one way but you have to explicitly write all these functions or methods that you want to import another way to do it is to say import num pi that's the same as we said they import math but give it an abbreviation so import num pi num pi is this beautiful beautiful module that can do all sorts of numerical calculations and I'm going to abbreviate it by this so if I run that python is extended itself but it's given it's imported this num pi module but it's given it an abbreviation so if I now want to refer to the cosine which lives inside of python I can just say np dot cosine I don't have to write out num pi as I had to write out math there so I'm going to say np dot cosine of the np dot pi and if I run that lo and behold of course it's also negative 1 so what we look at quickly is this using strings a variable can also contain other things not only integers floating point values you have to say a equals ok hello world ok here we go hello world and I've got to put it in these inverted commas now you can use double quotes or single quotes it doesn't matter I like single quotes but if you want if you want this to to be a string you've got to put it inside of these inverted commas so let's just run that if I now were to say a type in a and run it it's going to output that to the screen ok here we go hello world another way to do it but see these little quotation marks they've added them because that's the output it's trying to I suppose for lack of a better explanation trying to see it as a numerical value it's just putting these no need to what I've just said print a if I do that it's really just going to print out just the text ok here we go hello world I can attach something else to b now this is python and run that and I can now concatenate these two strings I can say a plus now that's another string I'm putting in there which is an empty space plus b I'm adding a space between these two strings because I'm using the plus concatenation so if I were to run that it's going to do them all in one go ok hello world ok here we go hello world this is python so it's added those two together I can use the print command and separate it with a comma then I don't need to add that space or anything funny like that if I were to run this it was going to concatenate them and put that little space in there ok here we go hello world this is python now for surprise what is a times 2 if I were to run it here we go ok here we go hello world ok here we go hello world so it's just going to output that twice let's put something else let's put something else into a so I've got these three integer values but I've enclosed them in the square bracket and that is what is called an array an array of values the first one is going to be called a 0 and this is going to be a 1 and this is going to be a 2 python always starts counting things from 0 so if I now output it a to the screen it's going to give me this whole thing and if I were to multiply an array by 2 it's not going to multiply each individual entry by 2 that would be a matrix that's something else it's just going to repeat this array twice 12 times 13 times 12, 13, 18, sorry 12, 13, 18 so it's just done it twice I can do a lot more with an array that's an integer that's an integer that's string text and that's just the computer variable B so I can put all sorts of things in there now you see it's 2, 3, hello and remember B was this is python so it'll put this is python there so that's an array and the very last thing there's some Boolean values what are Boolean values there's our first one a double equal sign and that is a question that I've asked the computer is whatever is in variable A equal to whatever is in variable B it asks that question so if I were to run that it's going to say false because remember A was okay here we go hello world and B was this is python and those two strings are definitely not the same this is the question mark the Boolean question mark a question I should say is not equal to so it's an exclamation mark equal so I'm asking is whatever is in A not equal to what is in B and definitely that is so so those whatever is inside of variable A and variable B are not the same so this will execute as true so let's just check that out one more time A equals I love math as a string A equals equals I love math so I'm asking is that what is inside of A at the moment yes it is true so that's your very quick introduction to a bit of coding more importantly the introduction to ipython notebook I think you can be familiar now with how the cells work and I've introduced just a tiniest bit of code nothing too difficult watch this lecture again work your way through this don't be scared to alter things, mess them about you've got to play with us to understand how it works this is all easy but the things that I've shown you here we are going to use in the in future for this lecture series and as you start manipulating your own data these are the common things that we're going to use over and over again really doesn't get much more difficult than this easy introduction to coding I hope you enjoyed it