Skip to content

Commit 1da76ec

Browse files
authored
Merge pull request #207 from QuantEcon/lec-review-2
Chapter 2 Review: Fixing Images and Exercise
2 parents 1742a3e + 39c4577 commit 1da76ec

File tree

10 files changed

+48
-25
lines changed

10 files changed

+48
-25
lines changed
102 KB
Loading
45.4 KB
Loading
40 KB
Loading
45.7 KB
Loading
121 KB
Loading
149 KB
Loading
104 KB
Loading
108 KB
Loading

lectures/getting_started.md

Lines changed: 47 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,18 @@ kernelspec:
1818
</div>
1919
```
2020

21+
<style>
22+
.auto {
23+
width: 70%;
24+
height: auto;
25+
}
26+
.terminal{
27+
width: 80%;
28+
height: auto;
29+
}
30+
</style>
31+
32+
2133
# Setting up Your Python Environment
2234

2335
```{index} single: Python
@@ -50,7 +62,7 @@ Hence the best approach for our purposes is to install a Python distribution tha
5062
1. the core Python language **and**
5163
1. compatible versions of the most popular scientific libraries.
5264

53-
The best such distribution is [Anaconda](https://www.anaconda.com/what-is-anaconda/).
65+
The best such distribution is [Anaconda](https://www.anaconda.com/products/distribution).
5466

5567
Anaconda is
5668

@@ -74,6 +86,7 @@ To install Anaconda, [download](https://www.anaconda.com/download/) the binary a
7486
Important points:
7587

7688
* Install the latest version!
89+
* Find the correct distribution for your system.
7790
* If you are asked during the installation process whether you'd like to make Anaconda your default Python installation, say yes.
7891

7992
### Updating Anaconda
@@ -114,13 +127,14 @@ Because of these features, Jupyter is now a major player in the scientific compu
114127
Here's an image showing execution of some code (borrowed from [here](http://matplotlib.org/examples/pylab_examples/hexbin_demo.html)) in a Jupyter notebook
115128

116129
```{figure} /_static/lecture_specific/getting_started/jp_demo.png
117-
:scale: 60
130+
:figclass: auto
118131
```
119132

120133
While Jupyter isn't the only way to code in Python, it's great for when you wish to
121134

122135
* start coding in Python
123136
* test new ideas or interact with small pieces of code
137+
* use powerful online interactive environments such as [Google Colab](https://research.google.com/colaboratory/)
124138
* share or collaborate scientific ideas with students or colleagues
125139

126140
These lectures are designed for executing in Jupyter notebooks.
@@ -141,7 +155,7 @@ Either
141155
If you use the second option, you will see something like this
142156

143157
```{figure} /_static/lecture_specific/getting_started/starting_nb.png
144-
:scale: 60
158+
:figclass: terminal
145159
```
146160

147161
The output tells us the notebook is running at `http://localhost:8888/`
@@ -154,7 +168,7 @@ Thus, the Jupyter kernel is listening for Python commands on port 8888 of our lo
154168
Hopefully, your default browser has also opened up with a web page that looks something like this
155169

156170
```{figure} /_static/lecture_specific/getting_started/nb.png
157-
:scale: 60
171+
:figclass: auto
158172
```
159173

160174
What you see here is called the Jupyter *dashboard*.
@@ -166,7 +180,7 @@ Assuming all this has worked OK, you can now click on `New` at the top right and
166180
Here's what shows up on our machine:
167181

168182
```{figure} /_static/lecture_specific/getting_started/nb2.png
169-
:scale: 60
183+
:figclass: auto
170184
```
171185

172186
The notebook displays an *active cell*, into which you can type Python commands.
@@ -189,7 +203,7 @@ In this mode, whatever you type will appear in the cell with the flashing cursor
189203
When you're ready to execute the code in a cell, hit `Shift-Enter` instead of the usual `Enter`.
190204

191205
```{figure} /_static/lecture_specific/getting_started/nb3.png
192-
:scale: 60
206+
:figclass: auto
193207
```
194208

195209
(Note: There are also menu and button options for running code in a cell that you can find by exploring)
@@ -205,9 +219,10 @@ The two modes are
205219
1. Edit mode
206220
* Indicated by a green border around one cell, plus a blinking cursor
207221
* Whatever you type appears as is in that cell
222+
208223
1. Command mode
209-
* The green border is replaced by a grey (or grey and blue) border
210-
* Keystrokes are interpreted as commands --- for example, typing b adds a new cell below the current one
224+
* The green border is replaced by a blue border
225+
* Keystrokes are interpreted as commands --- for example, typing `b` adds a new cell below the current one
211226

212227
To switch to
213228

@@ -275,13 +290,13 @@ After this import command, functions in NumPy can be accessed with `np.function_
275290

276291
We can explore these attributes of `np` using the `Tab` key.
277292

278-
For example, here we type `np.ran` and hit Tab
293+
For example, here we type `np.random.r` and hit Tab
279294

280295
```{figure} /_static/lecture_specific/getting_started/nb6.png
281-
:scale: 60
296+
:figclass: auto
282297
```
283298

284-
Jupyter offers up the two possible completions, `random` and `rank`.
299+
Jupyter offers several possible completions for you to choose from.
285300

286301
In this way, the Tab key helps remind you of what's available and also saves you typing.
287302

@@ -291,35 +306,37 @@ In this way, the Tab key helps remind you of what's available and also saves you
291306
```{index} single: Jupyter Notebook; Help
292307
```
293308

294-
To get help on `np.rank`, say, we can execute `np.rank?`.
309+
To get help on `np.random.randn`, we can execute `np.random.randn?`.
295310

296311
Documentation appears in a split window of the browser, like so
297312

298313
```{figure} /_static/lecture_specific/getting_started/nb6a.png
299-
:scale: 60
314+
:figclass: auto
300315
```
301316

302317
Clicking on the top right of the lower split closes the on-line help.
303318

319+
We will learn more about how to create documentation like this {ref}`later <Docstrings>`!
320+
304321
#### Other Content
305322

306323
In addition to executing code, the Jupyter notebook allows you to embed text, equations, figures and even videos in the page.
307324

308-
For example, here we enter a mixture of plain text and LaTeX instead of code
309-
310-
```{figure} /_static/lecture_specific/getting_started/nb7.png
311-
:scale: 60
312-
```
325+
For example, we can enter a mixture of plain text and LaTeX instead of code.
313326

314327
Next we `Esc` to enter command mode and then type `m` to indicate that we
315328
are writing [Markdown](http://daringfireball.net/projects/markdown/), a mark-up language similar to (but simpler than) LaTeX.
316329

317330
(You can also use your mouse to select `Markdown` from the `Code` drop-down box just below the list of menu items)
318331

332+
```{figure} /_static/lecture_specific/getting_started/nb7.png
333+
:figclass: auto
334+
```
335+
319336
Now we `Shift+Enter` to produce this
320337

321338
```{figure} /_static/lecture_specific/getting_started/nb8.png
322-
:scale: 60
339+
:figclass: auto
323340
```
324341

325342
### Sharing Notebooks
@@ -414,14 +431,14 @@ By convention, these text files have a `.py` extension.
414431
We can create an example of such a file as follows:
415432

416433
```{code-cell} ipython
417-
%%file foo.py
434+
%%writefile foo.py
418435
419436
print("foobar")
420437
```
421438

422439
This writes the line `print("foobar")` into a file called `foo.py` in the local directory.
423440

424-
Here `%%file` is an example of a [cell magic](http://ipython.readthedocs.org/en/stable/interactive/magics.html#cell-magics).
441+
Here `%%writefile` is an example of a [cell magic](http://ipython.readthedocs.org/en/stable/interactive/magics.html#cell-magics).
425442

426443
### Editing and Execution
427444

@@ -468,7 +485,7 @@ Alternatively, if you want an outstanding free text editor and don't mind a seem
468485

469486
## Exercises
470487

471-
```{exercise}
488+
```{exercise-start}
472489
:label: gs_ex1
473490
```
474491

@@ -490,6 +507,10 @@ You should now be able to run a standard Jupyter notebook session.
490507

491508
This is an alternative way to start the notebook that can also be handy.
492509

510+
This can also work when you accidentally close the webpage as long as the kernel is still running.
511+
512+
```{exercise-end}
513+
```
493514

494515
```{exercise-start}
495516
:label: gs_ex2
@@ -519,7 +540,7 @@ There are two main flavors of Git
519540

520541
1. the plain vanilla [command line Git](http://git-scm.com/downloads) version
521542
1. the various point-and-click GUI versions
522-
* See, for example, the [GitHub version](https://desktop.github.com/)
543+
* See, for example, the [GitHub version](https://desktop.github.com/) or Git GUI integrated into your IDE.
523544

524545
As the 1st task, try
525546

@@ -533,9 +554,10 @@ For example, if you've installed the command line version, open up a terminal an
533554
534555
git clone https://github.com/QuantEcon/QuantEcon.py
535556
```
536-
537557
(This is just `git clone` in front of the URL for the repository)
538558

559+
This command will download all necessary components to rebuild the lecture you are reading now.
560+
539561
As the 2nd task,
540562

541563
1. Sign up to [GitHub](https://github.com/).
@@ -547,7 +569,7 @@ As the 2nd task,
547569
For reading on these and other topics, try
548570

549571
* [The official Git documentation](http://git-scm.com/doc).
550-
* Reading through the docs on [GitHub](https://github.com/).
572+
* Reading through the docs on [GitHub](https://docs.github.com/en).
551573
* [Pro Git Book](http://git-scm.com/book) by Scott Chacon and Ben Straub.
552574
* One of the thousands of Git tutorials on the Net.
553575

lectures/python_essentials.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,7 @@ In Python, the standard style is set out in [PEP8](https://www.python.org/dev/pe
627627

628628
(Occasionally we'll deviate from PEP8 in these lectures to better match mathematical notation)
629629

630+
(Docstrings)=
630631
### Docstrings
631632

632633
```{index} single: Python; Docstrings

0 commit comments

Comments
 (0)