diff --git a/content/exercise.ipynb b/content/exercise.ipynb index 7f01224..84a41b8 100644 --- a/content/exercise.ipynb +++ b/content/exercise.ipynb @@ -11,7 +11,7 @@ "
\n", " \n", "# Python Crash Course\n", - "# Excercises\n", + "# Exercises\n", " \n", "
" ] @@ -20,7 +20,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## Excercise 1: Energy Levels of Hydrogen" + "## Exercise 1: Energy Levels of Hydrogen" ] }, { @@ -162,11 +162,11 @@ "id": "aOOniBHH40t1" }, "source": [ - "## Exercise 2: Primes numbers\n", + "## Exercise 2: Prime numbers\n", "\n", "In this exercise we will try to create a list of prime numbers. Assume we have a given number $N=100$, define it as a variable `N`.\n", "\n", - "- Create a list of integers from 2, 3, ... to `N`. Let's call this list `l_nums`. Is the list sorted? if not, sort it.\n", + "- Create a list of integers from 2, 3, ... to `N`. Let's call this list `l_nums`. Is the list sorted? If not, sort it.\n", " \n", "- Using a `for` loop, and `if else...` constructs, implement following: \n", " - Take the first element of the list, and remove all the higher multiples of it from the list.\n", diff --git a/content/notebook.ipynb b/content/notebook.ipynb index 5ef4679..57d93f1 100644 --- a/content/notebook.ipynb +++ b/content/notebook.ipynb @@ -83,7 +83,7 @@ "source": [ "As seen above we can add comments using `#` or `''' '''`. \n", "\n", - "It should be noted that unlike other languages we do not need to specify the type (or class) of this variable, that will simply be infered from the value it is given. Here `a` is an integer becuase we have set it to one. To display a variable's value we can use the `print()` function." + "It should be noted that unlike other languages we do not need to specify the type (or class) of this variable, that will simply be inferred from the value it is given. Here `a` is an integer because we have set it to 1. To display a variable's value we can use the `print()` function." ] }, { @@ -136,7 +136,7 @@ "id": "59b58928" }, "source": [ - "We can also check what class this varible is using the `type()` function as follows and we find that `a` is indeed an integer (denoted by `int`)." + "We can also check what class this variable is using the `type()` function as follows and we find that `a` is indeed an integer (denoted by `int`)." ] }, { @@ -190,8 +190,8 @@ }, "source": [ "- Once a variable stores a value, it can be used subsequently in an expression.\n", - "- An expression is usually mathematical expression, that once evaluated by python, yields a value of some type.\n", - "- We can also update the value of a variable in terms of it's old value. This may seem very strange as an equation but the `=` sign should be thought of as an assignment rather than an equals sign in the traditional mathematical sense." + "- An expression is usually a mathematical expression, that once evaluated by python, yields a value of some type.\n", + "- We can also update the value of a variable in terms of its old value. This may seem very strange as an equation but the `=` sign should be thought of as an assignment rather than an equals sign in the traditional mathematical sense." ] }, { @@ -250,7 +250,7 @@ "source": [ "## Operators\n", "\n", - "Python supports the usual operators for arithmatics.\n", + "Python supports the usual operators for arithmetics.\n", "\n", "- `+` denotes addition for numbers, `-` subtraction, and `*` multiplication.\n", "- `/` division for real numbers, `//` integer division.\n", @@ -320,9 +320,9 @@ "id": "8744d16d" }, "source": [ - "In the last cell you have have noted that I mixed floats and integers in a single operation and a float was returned.\n", + "In the last cell you might have noted that I mixed floats and integers in a single operation and a float was returned.\n", "\n", - "- Exponetial operation, i.e., $a^b$ is done using `**` operator. " + "- Exponential operation, i.e., $a^b$ is done using `**` operator. " ] }, { @@ -426,7 +426,7 @@ "\n", "`/` will always give float division.\n", "\n", - "If the integer version of these operations is required one can simply make both vaules an integer and use `//` for division (this will round down to the nearest integer)." + "If the integer version of these operations is required one can simply make both values an integer and use `//` for division (this will round down to the nearest integer)." ] }, { @@ -481,7 +481,7 @@ "id": "f06f54b3" }, "source": [ - "For those who are not familiar with other languages there is a modulo or remainder operation `%`. This is the remainder of a division operation which at first may not seem particulary useful but is actually a crucial operation in many algorithms. For example 3 divides into 20, 6 times with remainder 2 as shown." + "For those who are not familiar with other languages there is a modulo or remainder operation `%`. This is the remainder of a division operation which at first may not seem particularly useful but is actually a crucial operation in many algorithms. For example 3 divides into 20, 6 times with remainder 2 as shown." ] }, { @@ -688,11 +688,11 @@ "source": [ "## Comparison Operators and Boolean Variables\n", "\n", - "It is often important to compare two variables, and based on the result of comparison decide to a subsequent task. This is fundamental element in any programming.\n", + "It is often important to compare two variables, and, based on the result of the comparison, decide a subsequent task. This is a fundamental element in any programming.\n", "\n", - "- When we compare two object, they could be variables, or expressions that would evaluate to some value.\n", + "- We can compare variables, or expressions that would evaluate to some value.\n", "- Usually with numerical values, we have operators: \n", - " - i. Greather than `>`, or `>=` (greater than or equal to),\n", + " - i. Greater than `>`, or `>=` (greater than or equal to),\n", " - ii. Less than `<`, or `<=` (less than or equal to),\n", " - iii. equals `==`, or not equal `!=`.\n", "\n", @@ -823,14 +823,14 @@ }, "source": [ "## Complex Numbers\n", - "- Complex numbers in Python are expressed as `a + bj`, where a and b are float, or real literals. Here literal means a constant expression, such as 1.2, or 3, not a variable containing these values. Thus `2 + 3j` is a complex number which can be stored in a variable.\n", - "- `1j` is python equivalent to imaginary number $i$.\n", - "- The extraction of the real and imaginary parts is extracted as follows: If `z` is a complex number, then `z.real` and `z.imag` denote its real and imaginary part." + "- Complex numbers in Python are expressed as `a + bj`, where a and b are floats, or real literals. Here literal means a constant expression, such as 1.2, or 3, not a variable containing these values. Thus `2 + 3j` is a complex number which can be stored in a variable.\n", + "- `1j` is the python equivalent to imaginary number $i$.\n", + "- The real and imaginary parts are extracted as follows: If `z` is a complex number, then `z.real` and `z.imag` denote its real and imaginary part." ] }, { "cell_type": "code", - "execution_count": 36, + "execution_count": null, "id": "62a34515", "metadata": { "cell_id": "00035-9617d49b-dea7-454a-af9e-59368c4bea65", @@ -880,7 +880,7 @@ "print(z + w)\n", "print(z * w)\n", "\n", - "print() # just to seperate out our results\n", + "print() # just to separate out our results\n", "\n", "print(abs(z)) # the abs() function takes the modulus of the complex number\n", "\n", @@ -1069,7 +1069,7 @@ "id": "4xN_h1QNJdC3" }, "source": [ - "It is often useful to output variables intersperced in our text. A useful method to do this is the following," + "It is often useful to output variables interspersed in our text. A useful method to do this is the following," ] }, { @@ -1264,7 +1264,7 @@ }, { "cell_type": "code", - "execution_count": 43, + "execution_count": null, "id": "35653bc8", "metadata": { "cell_id": "00050-58af12d9-44e7-481e-a6c3-ce82330447df", @@ -1314,7 +1314,7 @@ "# slices off the section between character 7 (including) \n", "# and 14 (not including) \n", "\n", - "print('\\n') # just to seperate our outputs a bit\n", + "print('\\n') # just to separate our outputs a bit\n", "\n", "print(longer_string[:14]) \n", "print(longer_string[7:]) \n", @@ -1427,7 +1427,8 @@ "source": [ "## Casting\n", "\n", - "When we do mathematical operations on a piece of paper, we usually treat the integers, reals and complex on a kind of same footing, as `numbers`. However these numbers depending on what they are, they are saved and represented on a computer differently, based on type.\n", + "When we do mathematical operations on a piece of paper, we usually treat the integers, reals and complex on kind of the same footing, as `numbers`. However, depending on what they are, these numbers are saved and represented on a computer differently, based on their type.\n", + "\n", "- Integers are of type `int`, real numbers are of type `float`, and complex number are of type `complex`\n", "\n", "- Casting is a way of transforming one type of numerical value to another.\n", @@ -1509,7 +1510,7 @@ "## None Type\n", "Python has the null variable (denoted by `None`) which you might see used on occasion, it represents utter emptyness, or a symbolic object with no value and no (usual) type.\n", "\n", - "It should be noted what None is not;\n", + "NB what None is not:\n", "- `None` is not the same as `False`.\n", "- `None` is not `0`.\n", "- `None` is not an empty string. " @@ -1586,10 +1587,10 @@ "| Operator | Description |\n", "| :-: | :-: |\n", "| `()` | Parentheses |\n", - "| `**` | Exponentation |\n", + "| `**` | Exponentiation |\n", "| `+x`, `-x` | positive, negative |\n", "| `*`, `/`, `%` | multiplication, division, remainder |\n", - "| `+`, `-` | adition and subtraction |\n", + "| `+`, `-` | addition and subtraction |\n", "| `<`, `<=`, `>`, `>=`, `!=`, `==` | comparison operations |\n", "| `not x` | Boolean NOT |\n", "| `and` | Boolean AND |\n", @@ -1794,7 +1795,7 @@ "id": "43f614e1" }, "source": [ - "- Now that we have disscussed different data types we need a way to organise many pieces of data. \n", + "- Now that we have discussed different data types we need a way to organise many pieces of data. \n", "\n", "- This can be done using lists, tuples, sets, and dictionaries. \n", "\n", @@ -1802,7 +1803,7 @@ "\n", "
\n", "\n", - "| Type | Ordered | Changable | Allows Duplicates | Example |\n", + "| Type | Ordered | Changeable | Allows Duplicates | Example |\n", "| :-: | :-: | :-: | :-: | :-: |\n", "| List | ✔️ | ✔️ | ✔️ | [a,b] |\n", "| Tuple | ✔️ | ❌ | ✔️ | (a,b) |\n", @@ -1878,7 +1879,7 @@ "id": "p0w5iOQA5HUr" }, "source": [ - "One can access the elements of a lists by their placment starting with 0.\n", + "One can access the elements of a lists by their placement starting with 0.\n", "\n", "| `1` | `-2.0` | `\"Three\"` | `4+0j` | `None` |\n", "| :-: | :-: | :-: | :-: | :-: |\n", @@ -2172,7 +2173,7 @@ "id": "-QHA2vfn6yWB" }, "source": [ - "Access a value using it's key." + "Access a value using its key." ] }, { @@ -2483,7 +2484,7 @@ "source": [ "- To add to and remove from lists we use the `.append()` and `.remove()` attributes of the list class. \n", "\n", - "- We will discuss this structure in more detail in the object oriented programing portion of the course, however for now we can simply follow the syntax below." + "- We will discuss this structure in more detail in the object oriented programming portion of the course, however for now we can simply follow the syntax below." ] }, { @@ -2538,7 +2539,7 @@ "id": "llsNt5sYOu_q" }, "source": [ - "- Append will added to the end of the list but we can put our new item anywhere in our list using `.insert(,)`.\n", + "- Append will added to the end of the list but we can put our new item anywhere in our list using `.insert(,)`.\n", " \n", "- To delete an element `del()` can be used ; note that this is not an attribute of the list and can also be used on dictionaries." ] @@ -2763,7 +2764,7 @@ "id": "cgFbBOmy5RgR" }, "source": [ - "Or we slice incrementaly." + "Or we slice incrementally." ] }, { @@ -2804,7 +2805,7 @@ "source": [ "#This operation extracts the 0th element and takes two steps to extract the third and then fifth element.\n", "print(mylist[0::2])\n", - "#Simlary, starting at index 1\n", + "#Similarly, starting at index 1\n", "print(mylist[1::2])\n", "#If an index is omitted from the operation, it will be interpreted as 0, for example:\n", "print(mylist[::2])" @@ -2995,7 +2996,7 @@ "id": "6D_HfRA666Rs" }, "source": [ - "Lets define two sets, using these lists, and calulate their union and intersection. " + "Let's define two sets, using these lists, and caclulate their union and intersection. " ] }, { @@ -3227,7 +3228,7 @@ "id": "BxtKfgD7LsPJ" }, "source": [ - "This is cleary not the desired result; it seems `a` and `b` are now inextricably linked together by the `=` assignment. This is because when we refer to `a` in our code we are refering to the place where the list `a` is stored in our memory, we have therefore just com. This can be fixed by using `a.copy()` which will return a copy of the list which is what is desired." + "This is clearly not the desired result; it seems `a` and `b` are now inextricably linked together by the `=` assignment. This is because when we refer to `a` in our code we are referring to the place where the list `a` is stored in our memory, we have therefore just com. This can be fixed by using `a.copy()` which will return a copy of the list which is what is desired." ] }, { @@ -3292,7 +3293,7 @@ "metadata": {}, "source": [ "## Overview of Binary\n", - "- Why does 9 come berfore 10? It might seem like a silly question but the answer is that that is how humans have decided to write numbers. \n", + "- Why does 9 come before 10? It might seem like a silly question but the answer is that that is how humans have decided to write numbers. \n", "\n", "- That is that after ten numbers (0, 1, 2, 3, 4, 5, 6, 7, 8, and 9) we increase the ten's digit by one.\n", "\n", @@ -3520,7 +3521,7 @@ "source": [ "Following are key components for controlling flow of instructions in python programming.\n", "\n", - "* If Statments\n", + "* If Statements\n", "* Try and Except\n", "* While Loops\n", "* Range and Zip\n", @@ -3528,7 +3529,7 @@ "* Break, Continue, Pass\n", "\n", "\n", - "## If Statments \n", + "## If Statements \n", "\n", "We often require the execution certain code under specific conditions. For example there is a simple `if` statement that executes *if* the condition is satisfied.\n", "\n", @@ -3562,7 +3563,7 @@ "id": "5e923739", "metadata": {}, "source": [ - "**Note:** Make note also of the indentation as it is not just decoration, it is used by Python to seperate blocks of code.\n", + "**Note:** Make note also of the indentation as it is not just decoration, it is used by Python to separate blocks of code.\n", "\n", "There is a more complicated version where there are different parts of the code that execute under particular conditions. For example if x is true then do y, otherwise (else) do z. This is encapsulated in the `if`, `elif` (else if), and `else` statements. \n", "\n", @@ -3571,7 +3572,7 @@ }, { "cell_type": "code", - "execution_count": 57, + "execution_count": null, "id": "31c2e496", "metadata": {}, "outputs": [ @@ -3584,7 +3585,7 @@ } ], "source": [ - "#Feel free to experiment with the boolean value of the following condtions\n", + "#Feel free to experiment with the boolean value of the following conditions\n", "Condition1 = False\n", "Condition2 = True\n", "a=1\n", @@ -3716,7 +3717,7 @@ "id": "e443fbd8", "metadata": {}, "source": [ - "It should be noted that we can ommit either/both `elif` and `else` as well as having as many `elif`s as we want." + "It should be noted that we can omit either/both `elif` and `else` as well as having as many `elif`s as we want." ] }, { @@ -3738,7 +3739,7 @@ }, { "cell_type": "code", - "execution_count": 61, + "execution_count": null, "id": "c6c34950", "metadata": {}, "outputs": [ @@ -3755,7 +3756,7 @@ "try: # block of code...\n", " print(hi) # this should be a string, otherwise we are calling a variable name that hasn't be assigned a value so a NameError will be given.\n", " y = (1/0,5,7) # notice the 1/0 is not possible to compute and therefore a ZeroDivisionError error will be given\n", - " y[2] = 2 # y is a tupple wich cannot be changed so we will get a TypeError\n", + " y[2] = 2 # y is a tuple wich cannot be changed so we will get a TypeError\n", " \n", "except NameError: # executes variable's (or other object's) name is invalid\n", " print('there was a name error')\n", @@ -3843,12 +3844,12 @@ "id": "a4f446b2", "metadata": {}, "source": [ - "The range class is very useful for loops as we will see next. Lets explore it, and see how we can use lists to visualise it." + "The range class is very useful for loops as we will see next. Let's explore it, and see how we can use lists to visualise it." ] }, { "cell_type": "code", - "execution_count": 7, + "execution_count": null, "id": "045f7734", "metadata": {}, "outputs": [ @@ -3867,7 +3868,7 @@ "x = range(stop)\n", "print(type(x))\n", "print(x)\n", - "#Now lets cast to a list and print so we can see what this looks like\n", + "#Now let's cast to a list and print so we can see what this looks like\n", "\n", "x = list(x)\n", "\n", @@ -3879,7 +3880,7 @@ "id": "204df154", "metadata": {}, "source": [ - "Notice that we get a sequence running from 0-9, not 0-10!! It turns out we can add arguments in the parantheses to obtain a more specific sequence:" + "Notice that we get a sequence running from 0-9, not 0-10!! It turns out we can add arguments in the parentheses to obtain a more specific sequence:" ] }, { @@ -3949,7 +3950,7 @@ "id": "c23074b1", "metadata": {}, "source": [ - "The `zip()` function takes in two iterable data structures and returns an iterator of two object tupples as shown." + "The `zip()` function takes in two iterable data structures and returns an iterator of two object tuples as shown." ] }, { @@ -4251,7 +4252,7 @@ "id": "d455f3cb", "metadata": {}, "source": [ - "Using `continue` skips the rest of the code in that iteration of the loop and imediately moves onto the next." + "Using `continue` skips the rest of the code in that iteration of the loop and immediately moves onto the next." ] }, { @@ -4295,7 +4296,7 @@ "id": "2339a1a1", "metadata": {}, "source": [ - "The main function of `pass` is to fulfill a syntactical requirement; that is that something is required in a claus (bit of indented code after a colon (`:`). Often a useful placeholder that still alows for code to function when incomplete." + "The main function of `pass` is to fulfil a syntactical requirement; that is that something is required in a claus (bit of indented code after a colon (`:`). Often a useful placeholder that still alows for code to function when incomplete." ] }, { @@ -4586,7 +4587,7 @@ "\n", "Set comprehensions are the same as list comprehensions, except they use curly braces {} instead. \n", "\n", - "First lets use a list comprehension to get the following list:" + "First let's use a list comprehension to get the following list:" ] }, { @@ -4774,7 +4775,7 @@ "source": [ "##
Dictionary Comprehensions
\n", "\n", - "They also work similary with dictionaries." + "They also work similarly with dictionaries." ] }, { @@ -4867,7 +4868,7 @@ "source": [ "##
Generator Comprehensions
\n", "\n", - "A generator is simlar to a list except it does't allocate memory for each element in the list, but rather stores instructions to 'generate' the list. $\\bf{range()}$ is an example of a generator. Generators are often more memory efficient compared to lists.\n", + "A generator is similar to a list except it does't allocate memory for each element in the list, but rather stores instructions to 'generate' the list. $\\bf{range()}$ is an example of a generator. Generators are often more memory efficient compared to lists.\n", "\n", "These are essentially the same as list comprehensions, we use regular brackets '()' instead of square brackets." ] @@ -5245,7 +5246,7 @@ "id": "97021205", "metadata": {}, "source": [ - "We can actually have an `if`/`else` condition in a single line. Lets say we have two variables `a` and `b`." + "We can actually have an `if`/`else` condition in a single line. Let's say we have two variables `a` and `b`." ] }, { @@ -5293,7 +5294,7 @@ "id": "64d172e9", "metadata": {}, "source": [ - "But we can acually write this as " + "But we can actually write this as " ] }, { @@ -5422,7 +5423,7 @@ "id": "9d99139f", "metadata": {}, "source": [ - "This is better than not having a loop at all but is still a little clumbsy. We can in fact have a loop inside the assignment of the list. The following makes a list containing the values `j` (which will often depend on `i`) for each value `i` in the interable `it`\n", + "This is better than not having a loop at all but is still a little clumsy. We can in fact have a loop inside the assignment of the list. The following makes a list containing the values `j` (which will often depend on `i`) for each value `i` in the interable `it`\n", "\n", "```l = [j for i in iter]```.\n", "\n", @@ -5482,7 +5483,7 @@ "id": "8f234ad0", "metadata": {}, "source": [ - "Or prehaps more simply" + "Or perhaps more simply" ] }, { @@ -5612,9 +5613,9 @@ "\n", "Recall the for loop: `for i in some_list` or list comprehension `[i for i in some_list]`. Here `i` is the iterated variable, that get's different value, and `some_list` in general is an object, that once supplied to the for loop, provides those values. Such objects are called generators.\n", "\n", - "- Instead of an iterable containing all of it's elements generators distinguish themselves by storing the information to generate elements.\n", + "- Instead of an iterable containing all of its elements generators distinguish themselves by storing the information to generate elements.\n", "\n", - "- The function `range()` is in fact a generator. We can make our own generators with a similar sintax to what is used in comprehensions except now with `()`." + "- The function `range()` is in fact a generator. We can make our own generators with a similar syntax to what is used in comprehensions except now with `()`." ] }, { @@ -5686,17 +5687,17 @@ "id": "cf47bf74", "metadata": {}, "source": [ - "The `input()` function can be used to ask for and take in data from the user. Try running the cell below, enter space seperated integers in the field, and then press return." + "The `input()` function can be used to ask for and take in data from the user. Try running the cell below, enter space separated integers in the field, and then press return." ] }, { "cell_type": "code", - "execution_count": 74, + "execution_count": null, "id": "9b141edc", "metadata": {}, "outputs": [], "source": [ - "entry = input('enter space seperated integers: ')" + "entry = input('enter space separated integers: ')" ] }, { @@ -5704,7 +5705,7 @@ "id": "38b51dbb", "metadata": {}, "source": [ - "The data is now stored as a single string called `entry`. This is not particularly useful for working with this data. We shoud put this data into a list and make each element the integer entered." + "The data is now stored as a single string called `entry`. This is not particularly useful for working with this data. We should put this data into a list and make each element the integer entered." ] }, { @@ -5735,12 +5736,12 @@ "id": "7fe2ca67", "metadata": {}, "source": [ - "Remebering what we learened about compactifying our code we can write this all in one line." + "Remembering what we learened about compactifying our code we can write this all in one line." ] }, { "cell_type": "code", - "execution_count": 76, + "execution_count": null, "id": "004f410b", "metadata": {}, "outputs": [ @@ -5753,7 +5754,7 @@ } ], "source": [ - "l = [int(i) for i in input('enter space seperated integers: ').split()]\n", + "l = [int(i) for i in input('enter space separated integers: ').split()]\n", "print(l)" ] }, @@ -5790,9 +5791,9 @@ "source": [ "- The file `test.txt` is stored in the same directory as this notebook to save specifying a path.\n", "\n", - "- The `'r'` argument in the open function specifies that we are opening this file for reading so this file cannont be editted while open in this way.\n", + "- The `'r'` argument in the open function specifies that we are opening this file for reading so this file cannont be edited while open in this way.\n", "\n", - "- Within the indented clause the file can be refered to as `f`. \n", + "- Within the indented clause the file can be referred to as `f`. \n", "\n", "- We can also iterate through the file which will get each line as a string." ] @@ -5844,7 +5845,7 @@ "id": "53306da8", "metadata": {}, "source": [ - "Let's say we want to store a list of the first 11 sqaure numbers. First it might be good to make such a list." + "Let's say we want to store a list of the first 11 square numbers. First it might be good to make such a list." ] }, { @@ -5971,7 +5972,7 @@ "source": [ "## [2.1 Flow Control](Week2_Notebooks/PyQM_2.1_Flow_Control.ipynb) \n", "\n", - "- If Statments\n", + "- If Statements\n", " - Documentation: https://docs.python.org/3/tutorial/controlflow.html\n", "\n", " ```\n", @@ -6036,7 +6037,7 @@ "- One-Line If and Else\n", " - Documentation: https://www.codegrepper.com/code-examples/python/python+single+line+for+loop+with+if+else\n", " ```\n", - " x = one_thing if condtion else another_thing\n", + " x = one_thing if condition else another_thing\n", " ```\n", "- Comprehensions\n", " - Documentation: https://docs.python.org/3/tutorial/datastructures.html#list-comprehensions\n", @@ -6553,7 +6554,7 @@ "id": "7d2bec5c" }, "source": [ - "We set the argument to a commonly used value in the parantheses. We can now call this function without specifying the third argument \"z\"." + "We set the argument to a commonly used value in the parentheses. We can now call this function without specifying the third argument \"z\"." ] }, { @@ -6653,7 +6654,7 @@ "id": "de6d626d" }, "source": [ - "When using default arguments, you must be wary of using mutable objects like lists. Lets illustrate this in the following example." + "When using default arguments, you must be wary of using mutable objects like lists. Let's illustrate this in the following example." ] }, { @@ -6835,7 +6836,7 @@ "source": [ "### Unknown Amount Of Arguments, `*args`\n", "\n", - "You may need to define a function in which want to input varying numbers of arguments. To do this, we precede the argumentsw with `*` For example" + "You may need to define a function in which want to input varying numbers of arguments. To do this, we precede the arguments with `*` For example" ] }, { @@ -7008,7 +7009,7 @@ "source": [ "## Global And Local Variables\n", "\n", - "Global variables are defined outside of functions. Local Variables are defined inside functions. We can use gloabl variables both outside and inside a function. However local variable can only be used inside a function. For example" + "Global variables are defined outside of functions. Local Variables are defined inside functions. We can use global variables both outside and inside a function. However local variable can only be used inside a function. For example" ] }, { @@ -7124,7 +7125,7 @@ "source": [ "## Lambda Functions\n", "\n", - "Lambda functions are compactified, unnamed functions that are very commonly used in cojunction with lists." + "Lambda functions are compactified, unnamed functions that are very commonly used in conjunction with lists." ] }, { @@ -7314,7 +7315,7 @@ "id": "8c2ff2a8" }, "source": [ - "We can also also add more arguments, or lists, allowing us to perform various operations on multiple lists." + "We can also add more arguments, or lists, allowing us to perform various operations on multiple lists." ] }, { @@ -7910,7 +7911,7 @@ "id": "dcfc4436" }, "source": [ - "Lets define the class in a slighly different way" + "Let's define the class in a slightly different way" ] }, { @@ -7942,7 +7943,7 @@ "id": "4b90241b" }, "source": [ - "This begs the questions, how do we call the `n` or `name` method attribute. Lets find out." + "This begs the questions, how do we call the `n` or `name` method attribute. Let's find out." ] }, { @@ -8032,7 +8033,7 @@ "source": [ "## Magic Methods\n", "\n", - "Here lets introduce some common magic methods\n", + "Here let's introduce some common magic methods\n", "\n", "### `__init__()`\n", "\n", @@ -8142,7 +8143,7 @@ "id": "009bf5f1" }, "source": [ - "In the `__init__()` method we declare the instance variables bvy assigning them to `self`. They can then be accessed in other methods using `self`." + "In the `__init__()` method we declare the instance variables by assigning them to `self`. They can then be accessed in other methods using `self`." ] }, { @@ -8453,7 +8454,7 @@ "id": "a7d8b02e" }, "source": [ - "Lets attempt to override the `+` operator so that elements of the list are added not concatenated. To do this, we will create a whole new data type or class called `Spooky_List`, where adding two `Spooky_Lists` adds their elements rather than concatenating them." + "Let's attempt to override the `+` operator so that elements of the list are added not concatenated. To do this, we will create a whole new data type or class called `Spooky_List`, where adding two `Spooky_Lists` adds their elements rather than concatenating them." ] }, { @@ -8546,7 +8547,7 @@ "id": "fc61d7a5" }, "source": [ - "The `__add__` magic method here corresponds to the operator `+`. Similary we have \n", + "The `__add__` magic method here corresponds to the operator `+`. Similarly we have \n", "\n", "| Operator | Operator\tMagic Method |\n", "| :-: | :-: | \n", @@ -8629,7 +8630,7 @@ "id": "b40327d9" }, "source": [ - "We get an error, which makes sense, as there is no reason the methods for lists should work for `Spooky_Lists`. So lets make our own using `__getitem__()`. We will also use `__setitem__()` so that we can assign value to certain indexes in our `Spooky_List`. Lets also add a `__str__()` so we can print our Spooky_Lists" + "We get an error, which makes sense, as there is no reason the methods for lists should work for `Spooky_Lists`. So let's make our own using `__getitem__()`. We will also use `__setitem__()` so that we can assign value to certain indexes in our `Spooky_List`. Let's also add a `__str__()` so we can print our Spooky_Lists" ] }, { @@ -8791,7 +8792,7 @@ "id": "IA6oukp7YtSZ" }, "source": [ - "Lets use a list as our \"object\" and also set the data type to \"float\"." + "Let's use a list as our \"object\" and also set the data type to \"float\"." ] }, { @@ -8847,7 +8848,7 @@ "id": "2gD9t3CLY7Gi" }, "source": [ - "We can similary use a tuple, or any array-like object, in the definition." + "We can similarly use a tuple, or any array-like object, in the definition." ] }, { @@ -9655,7 +9656,7 @@ "id": "nByyGvXdl8es" }, "source": [ - "Lets use the $np.matmul()$ method to multiply two matrices. First note that order of multiplication with matrices matters!" + "Let's use the $np.matmul()$ method to multiply two matrices. First note that order of multiplication with matrices matters!" ] }, { @@ -9718,7 +9719,7 @@ "id": "COv6UjPrlIP6" }, "source": [ - "Now lets multiply three matrices together, $$HXH$$\n", + "Now let's multiply three matrices together, $$HXH$$\n", "We can nest the $np.matmul()$ to accomplish this faster" ] }, @@ -9770,7 +9771,7 @@ "id": "9NkpInDHh6ri" }, "source": [ - "We get an ugly answer because we are using floats of an irrational number $\\frac{1}{\\sqrt{2}}$, but notice the negligibility of numbers of order $10^{-17}$. Lets tidy this up with the $np.round()$ method\n", + "We get an ugly answer because we are using floats of an irrational number $\\frac{1}{\\sqrt{2}}$, but notice the negligibility of numbers of order $10^{-17}$. Let's tidy this up with the $np.round()$ method\n", "\n", "```np.round(array, decimals=0)```" ] @@ -9835,7 +9836,7 @@ "id": "PuLgpkgpnAx1" }, "source": [ - "Now lets make a 2-dimensional vector" + "Now let's make a 2-dimensional vector" ] }, { @@ -9887,7 +9888,7 @@ "id": "Z2lRlk1wpYD-" }, "source": [ - "Lets rotate it by multiplying it by the X matrix.(Recall week 2 exercises). " + "Let's rotate it by multiplying it by the X matrix.(Recall week 2 exercises). " ] }, { @@ -11295,7 +11296,7 @@ "\n", "```arr[lower:upper:step]```\n", "\n", - "Slicing is a dynamical way to extract certain parts of an array. Lets create a list and slice it up" + "Slicing is a dynamical way to extract certain parts of an array. Let's create a list and slice it up" ] }, { @@ -11572,7 +11573,7 @@ "id": "Z0U42qPBDv6O" }, "source": [ - "Lets try to input negative indexes" + "Let's try to input negative indexes" ] }, { @@ -11720,7 +11721,7 @@ "id": "dkPd5gviG5Rz" }, "source": [ - "Lets look at slicing 2-d arrays. It works in the same way:" + "Let's look at slicing 2-d arrays. It works in the same way:" ] }, { @@ -12179,7 +12180,7 @@ "source": [ "```arr.ravel()```\n", "\n", - "We can similary use $ravel()$" + "We can similarly use $ravel()$" ] }, { @@ -13917,7 +13918,7 @@ "tags": [] }, "source": [ - "Lets create two NumPy arrays each containing the $x$- and $y$-coordinates respectively of a two points, $(0,1)$ and $(3,5)$. The `plt.plot()` function in Matplotlib can be used to plot the line between these two points." + "Let's create two NumPy arrays each containing the $x$- and $y$-coordinates respectively of a two points, $(0,1)$ and $(3,5)$. The `plt.plot()` function in Matplotlib can be used to plot the line between these two points." ] }, { @@ -14196,7 +14197,7 @@ "id": "96abade0", "metadata": {}, "source": [ - "or prehaps more elegantly" + "or perhaps more elegantly" ] }, { @@ -15491,7 +15492,7 @@ "id": "62850185", "metadata": {}, "source": [ - "Making multiple plots can often be very useful. There are a number of ways to do this, prehaps the quickest is using `plt.subplot()`. The first two arguments are defining the grid shape (row then column) and the third will be the number within this grid, counting horizontally before vertical as shown. After we have specified the plot we can use the familiar functions we are used to like `plt.plot`, `plt.titles`, etc. The function `plt.suptitle()` can be used to give a title to the entire figure. " + "Making multiple plots can often be very useful. There are a number of ways to do this, perhaps the quickest is using `plt.subplot()`. The first two arguments are defining the grid shape (row then column) and the third will be the number within this grid, counting horizontally before vertical as shown. After we have specified the plot we can use the familiar functions we are used to like `plt.plot`, `plt.titles`, etc. The function `plt.suptitle()` can be used to give a title to the entire figure. " ] }, { @@ -15747,7 +15748,7 @@ "id": "ad5c0ace", "metadata": {}, "source": [ - "While repeatedly adding axes to the figure does give a lot of control, specifying placement for a lange number of plots could become laborious. The function `fig.add_subplot()` can become very useful for this particulary for iterative creation of plots. `fig.subplots_adjust()` is often necessary to spread the plots out." + "While repeatedly adding axes to the figure does give a lot of control, specifying placement for a lange number of plots could become laborious. The function `fig.add_subplot()` can become very useful for this particularly for iterative creation of plots. `fig.subplots_adjust()` is often necessary to spread the plots out." ] }, { @@ -15801,7 +15802,7 @@ "id": "aba94ea7", "metadata": {}, "source": [ - "Another method of having the acheving a similar but prehaps more versitile result is to first make an empty figure object using `plt.subplots()` to create a figure object and a tupple of axes within that. As seen below `plt.subplots()` returns both a figure, `fig` and a numpy array of axes, `ax`. Within `plt.subplots()` one can specify the number and shape of axes with `ax`; e.g `plt.subplots(2,1)` creates a figure with two rows with one set axes each. " + "Another method of having the acheving a similar but perhaps more versitile result is to first make an empty figure object using `plt.subplots()` to create a figure object and a tuple of axes within that. As seen below `plt.subplots()` returns both a figure, `fig` and a numpy array of axes, `ax`. Within `plt.subplots()` one can specify the number and shape of axes with `ax`; e.g `plt.subplots(2,1)` creates a figure with two rows with one set axes each. " ] }, { @@ -16034,7 +16035,7 @@ "There are some other costomizability options for plots that are very useful in histograms.\n", "- `.invert_xaxis()` and `.invert_yaxis()` : Flips either axis.\n", "- `.xaxis.tick_top()` and `.yaxis.tick_right()` : Changes side ticks appear on.\n", - "- `.get_shared_x_axes().join(ax1, ax2)` and `.get_shared_y_axes().join(ax1, ax2)` : Creates a link between the two axes so that they scale together. This is useful if the axes have been created seperately by `fig.add_axes()` as opposed to and subplot technique.\n", + "- `.get_shared_x_axes().join(ax1, ax2)` and `.get_shared_y_axes().join(ax1, ax2)` : Creates a link between the two axes so that they scale together. This is useful if the axes have been created separately by `fig.add_axes()` as opposed to and subplot technique.\n", "The `orientation` keyword can be changed to `'horizontal'` to flip the chart on its side." ] }, @@ -16105,7 +16106,7 @@ "tags": [] }, "source": [ - "We have seen `plt.plot()` where you remove the lines between the points but prehaps a better way of diaplaying the same thing is using `plt.scatter()`." + "We have seen `plt.plot()` where you remove the lines between the points but perhaps a better way of diaplaying the same thing is using `plt.scatter()`." ] }, { @@ -16369,7 +16370,7 @@ "id": "913f7525", "metadata": {}, "source": [ - "Using the `explode` keyword we can highlight and seperate the segments. This is set to a list or numpy array with the same length as the number of segments that sets how seperated each segment is." + "Using the `explode` keyword we can highlight and separate the segments. This is set to a list or numpy array with the same length as the number of segments that sets how separated each segment is." ] }, { @@ -16542,7 +16543,7 @@ "id": "3dd77107", "metadata": {}, "source": [ - "For plotting a surface it is best to create a 2D mesh grid of points using `np.meshgrid()`; this takes in two numpy arrays that can be thought of as $x$ and $y$ axes to this grid. Lets say the arrays are of lengths $m$ and $n$. The function creates two $n \\times m$ matrices; one with rows eqaul to the $x$-array and one with the columns equal to $y$-array." + "For plotting a surface it is best to create a 2D mesh grid of points using `np.meshgrid()`; this takes in two numpy arrays that can be thought of as $x$ and $y$ axes to this grid. Let's say the arrays are of lengths $m$ and $n$. The function creates two $n \\times m$ matrices; one with rows eqaul to the $x$-array and one with the columns equal to $y$-array." ] }, { @@ -16894,7 +16895,7 @@ "id": "de415d59", "metadata": {}, "source": [ - "Now keeping this active we will add a plot to the picture. Notice that when we plot we have saved the return `line` item. The `,` is present because this is in `ax.plot()` will in fact return a tupple with the needed item as the first item." + "Now keeping this active we will add a plot to the picture. Notice that when we plot we have saved the return `line` item. The `,` is present because this is in `ax.plot()` will in fact return a tuple with the needed item as the first item." ] }, { @@ -18169,7 +18170,7 @@ "$$ y = c_1 x^2 + c_2 x.$$\n", "We will generate data points by adding noise to this function for certain values of $c_1$ and $c_2$. We will then then try to fit the noisy data with `scipy.linalg.lstsq(A, c)`, comparing our approximate values of $c_i$ to the actual values.\n", "\n", - "Lets set \n", + "Let's set \n", "$$ c_1 = 0.5$$ and $$ c_2 = 2.0$$\n", "$A$ is a matrix of the set of functions, of $x$, describing $y$. So in this case\n", "$$ A = [x^2,x]$$" @@ -18826,7 +18827,7 @@ "id": "4a9398cc", "metadata": {}, "source": [ - "Lets try and fit a curve to the following noisy data." + "Let's try and fit a curve to the following noisy data." ] }, { @@ -19207,7 +19208,7 @@ "id": "ccd7b295", "metadata": {}, "source": [ - "Now lets perform a Fourier transform." + "Now let's perform a Fourier transform." ] }, { @@ -19504,7 +19505,7 @@ "\n", "$$ |q> = \\frac{1}{\\sqrt{2}}|0> + \\frac{1}{\\sqrt{2}}|1>$$\n", "\n", - "We can therefore fully represent this state in an array with elements $x_j$. We can change to another basis of states using a discrete fourier transform(with normalisation constant $1/\\sqrt{N}$), changing the amplitudes $x_j$.\n", + "We can therefore fully represent this state in an array with elements $x_j$. We can change to another basis of states using a discrete fourier transform (with normalisation constant $1/\\sqrt{N}$), changing the amplitudes $x_j$.\n", "\n", "$$y_k = \\frac{1}{\\sqrt{N}}\\sum_{j=0}^{N-1}x_j e^{-2\\pi i k \\frac{j}{N} }$$\n", "\n", @@ -19514,7 +19515,7 @@ "\n", "But this is just the same as using the discrete fourier transform in the above sections. \n", "\n", - "Lets do an example, applying a quantum fourier transform to the following qubit\n", + "Let's do an example, applying a quantum fourier transform to the following qubit\n", "\n", "$$ |x> = x_0|0> + x_1|1>$$\n", "\n", @@ -19522,7 +19523,7 @@ "\n", "$$y_1 = \\frac{1}{\\sqrt{2}}(x_0e^{-2\\pi i \\frac{1\\times 0}{2}} + x_1e^{-2\\pi i \\frac{1\\times 1}{2}}) = \\frac{1}{\\sqrt{2}}(x_0 - x_1) $$\n", "\n", - "Lets impliment this in scipy." + "Let's impliment this in scipy." ] }, { @@ -19902,7 +19903,7 @@ "id": "6e48ec10", "metadata": {}, "source": [ - "The function `scipy.integrate.quad(f,a,b)` integrates a function `f(x)` between the bounds [`a`,`b`] using a technique from the Fortran library QUADPACK and returns the value `y` of the definite integral integral and the error in this calculation,\n", + "The function `scipy.integrate.quad(f,a,b)` integrates a function `f(x)` between the bounds [`a`,`b`] using a technique from the Fortran library QUADPACK and returns the value `y` of the definite integral and the error in this calculation,\n", "$$y = \\int_a^b f(x)\\ dx.$$" ] }, @@ -20116,13 +20117,13 @@ "source": [ "A first order ODE is an equation of the form\n", "$$\\frac{dy}{dt} = f(t,y). $$\n", - "Lets do an example of radioactive decay, and how we can use scipy to solve an ode. \n", + "Let's do an example of radioactive decay, and how we can use scipy to solve an ODE. \n", "\n", - "The half life of carbon-14 is 5700 years. It's corrseponding decay constant is given by the formula\n", + "The half life of carbon-14 is 5700 years. Its corrseponding decay constant is given by the formula\n", "$$k = \\frac{ln(\\frac{1}{2})}{5700} = -0.0001216$$\n", - "We can write an ordinary differential equation that encapsulates radioactive, exponential decay as follows\n", - "$$\\frac{dy}{dt} = k*y $$\n", - "Lets solve this, for an initial $100$g sample of carbon-14, using `scipy.integrate.solve_ivp(fun, t_span, y0, method='RK45',t_eval=None)`. This solves an ODE, given an initial value `y0`, over a time span `t_span`, where the right hand side of the above equation is given by `fun`. The method of integration is set to fourth-order Runge-Kutta by default. `t_eval` can be set to an array that specifies the times at which to store the solution, otherwise this is set by default. The function returns multiple attributes, most importantly `.t` and `.y` which give the stored times and $y$-values for the solution." + "We can write an ordinary differential equation that encapsulates radioactive, exponential decay as \n", + "$\\frac{dy}{dt} = k*y $.\n", + "Let's solve this, for an initial 100g sample of carbon-14, using `scipy.integrate.solve_ivp(fun, t_span, y0, method='RK45',t_eval=None)`. This solves an ODE, given an initial value `y0`, over a time span `t_span`, where the right-hand side of the above equation is given by `fun`. The method of integration is set to fourth-order Runge-Kutta by default. `t_eval` can be set to an array that specifies the times at which to store the solution, otherwise this is set by default. The function returns multiple attributes, most importantly `.t` and `.y` which give the stored times and $y$-values for the solution." ] }, { @@ -20168,7 +20169,7 @@ "id": "757be98a", "metadata": {}, "source": [ - "We can also solve for multiple initial values of `y`, in other words that `y0` can be an array. Here we have solution for $100$g, $50$g, and $10$g of carbon-14." + "We can also solve for multiple initial values of `y` — in other words, `y0` can be an array. Here we have solution for $100$g, $50$g, and $10$g of carbon-14." ] }, { @@ -20238,7 +20239,7 @@ "\n", "$$f(x_0 + h) = f(x_0) + \\frac{f'(x_0)}{1!}h + \\frac{f''(x_0)}{2!}h^2 + ... + \\frac{f^{(n)}(x_0)}{n!}h^n + R_n(x) $$\n", "\n", - "Lets start by truncating the series at $n=1$, assuming that the remainder $R_1(x)$ can be neglected.\n", + "Let's start by truncating the series at $n=1$, assuming that the remainder $R_1(x)$ can be neglected.\n", "\n", "$$f(x_0 + h) \\approx f(x_0) + \\frac{f'(x_0)}{1!}h $$\n", "\n", @@ -20260,7 +20261,7 @@ "id": "ab1d0bd5", "metadata": {}, "source": [ - "Lets do the something similar for the second derivative\n", + "Let's do something similar for the second derivative\n", "\n", "$$f(x_0 + h) \\approx f(x_0) + \\frac{f'(x_0)}{1!}h + \\frac{f''(x_0)}{2!}h^2 $$\n", "$$f(x_0 - h) \\approx f(x_0) - \\frac{f'(x_0)}{1!}h + \\frac{f''(x_0)}{2!}h^2 $$\n", @@ -20298,7 +20299,7 @@ "\n", "Notice, that we can classify this as a sparse matrix, and leverage this using scipy.\n", "\n", - "Lets test this on $\\frac{x^3}{6}$, where $\\frac{d^2}{dx^2}\\frac{x^3}{6}=x$" + "Let's test this on $\\frac{x^3}{6}$, where $\\frac{d^2}{dx^2}\\frac{x^3}{6}=x$" ] }, { @@ -20371,7 +20372,7 @@ "id": "77a1be4c", "metadata": {}, "source": [ - "Lets use the above function to solve a PDE, namely the time-independent Schrödinger equation in one-dimension:\n", + "Let's use the above function to solve a PDE, namely the time-independent Schrödinger equation in one-dimension:\n", "$$\\frac{-\\hbar^2}{2m}\\frac{\\partial{}^2}{\\partial{x^2}}\\psi(t,x) + V(x)\\psi(t,x) = i\\hbar \\frac{\\partial{}}{\\partial{t}}\\psi(t,x) $$\n", "\n", "We can rewrite this equation in the following way\n", @@ -20440,11 +20441,11 @@ "id": "7198be77", "metadata": {}, "source": [ - "We will define our initial state $\\psi(t=0)$ as that of a wave packet scene in the previous section 6.4\n", + "We will define our initial state $\\psi(t=0)$ as that of a wave packet seen in the previous section 6.4\n", "\n", "$$\\psi(x) = \\frac{1}{(\\pi \\sigma^2)^{\\frac{1}{4}}}e^{-\\frac{(x-x_0)^2}{2\\sigma^2}}e^{ifx} $$\n", "\n", - "Where $\\sigma$ is the width, $x_0$ is it's position, and $f$ is it's frequency." + "Where $\\sigma$ is the width, $x_0$ is it's position, and $f$ is its frequency." ] }, { @@ -20488,7 +20489,7 @@ "id": "fe69a80b", "metadata": {}, "source": [ - "Now lets plot" + "Now let's plot" ] }, { @@ -20992,7 +20993,7 @@ "id": "52313aa9", "metadata": {}, "source": [ - "There are many distributions available with `scipy.stats`. A full List can be found at [here](https://docs.scipy.org/doc/scipy/reference/reference/stats.html#module-scipy.stats). The following can be extracted once the distribution is created:\n", + "There are many distributions available with `scipy.stats`. A full list can be found [here](https://docs.scipy.org/doc/scipy/reference/reference/stats.html#module-scipy.stats). The following can be extracted once the distribution is created:\n", "- `.pdf`: **P**robability **D**istribution **F**unction,\n", "- `.pmf`: **P**robability **M**ass **F**unction,\n", "- `.cdf`: **C**umlative **D**istribution **F**unction,\n",