Skip to content

Commit d3366ea

Browse files
authored
Merge pull request #304 from QuantEcon/updates_to_intros
Updates to first few lectures
2 parents 2937f87 + e095771 commit d3366ea

File tree

4 files changed

+89
-414
lines changed

4 files changed

+89
-414
lines changed

lectures/about_py.md

Lines changed: 39 additions & 278 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,14 @@ Our only objective for this lecture is to give you some feel of what Python is,
5353

5454
Python is free and open source, with development coordinated through the [Python Software Foundation](https://www.python.org/psf/).
5555

56-
Python has experienced rapid adoption in the last decade and is now one of the [most popular programming languages](https://pythoncircle.com/post/763/the-rising-popularity-of-python/).
56+
Python has experienced rapid adoption in the last decade and is now one of the [most popular programming languages](https://www.tiobe.com/tiobe-index/).
5757

5858
### Common Uses
5959

6060
{index}`Python <single: Python; common uses>` is a general-purpose language used in almost all application domains such as
6161

62-
* communications
62+
* AI
63+
* communication
6364
* web development
6465
* CGI and graphical user interfaces
6566
* game development
@@ -75,16 +76,14 @@ Used and supported extensively by Internet services and high-tech companies incl
7576
* [Amazon](https://www.amazon.com/)
7677
* [Reddit](https://www.reddit.com/)
7778

78-
For reasons we will discuss, Python is particularly popular within the scientific community and behind many scientific achievements in
79-
* [Space Science](https://code.nasa.gov/?q=python)
80-
* [Particle Physics](https://home.cern/news/news/physics/speeding-machine-learning-particle-physics)
81-
* [Genetics](https://github.com/deepmind/alphafold)
79+
For reasons we will discuss, Python is particularly popular within the scientific community
8280

83-
and practically all branches of academia.
81+
Meanwhile, Python is also very beginner-friendly and is found to be suitable for
82+
students learning programming and recommended to introduce computational methods
83+
to students in fields other than computer science.
8484

85-
Meanwhile, Python is also very beginner-friendly and is found to be suitable for students learning programming and recommended to introduce computational methods to students in [fields other than computer science](https://www.sciencedirect.com/science/article/pii/S1477388021000177).
85+
Python is also replacing familiar tools like Excel as an essential skill in the fields of finance and banking.
8686

87-
Python is also [replacing familiar tools like Excel as an essential skill](https://www.efinancialcareers.com.au/news/2021/08/python-for-banking-jobs) in the fields of finance and banking.
8887

8988
### Relative Popularity
9089

@@ -95,23 +94,8 @@ The following chart, produced using Stack Overflow Trends, shows one measure of
9594

9695
The figure indicates not only that Python is widely used but also that adoption of Python has accelerated significantly since 2012.
9796

98-
We suspect this is driven at least in part by uptake in the scientific
99-
domain, particularly in rapidly growing fields like data science.
97+
This is driven at least in part by uptake in the scientific domain, particularly in rapidly growing fields like data science and AI.
10098

101-
For example, the popularity of [pandas](http://pandas.pydata.org/), a library for data analysis with Python has exploded, as seen here.
102-
103-
(The corresponding time path for MATLAB is shown for comparison)
104-
105-
```{figure} /_static/lecture_specific/about_py/pandas_vs_matlab.png
106-
```
107-
108-
Note that pandas takes off in 2012, which is the same year that we see
109-
Python's popularity begin to spike in the first figure.
110-
111-
Overall, it's clear that
112-
113-
* Python is [one of the most popular programming languages worldwide](https://spectrum.ieee.org/top-programming-languages-2021).
114-
* Python is a major tool for scientific computing, accounting for a rapidly rising share of scientific work around the globe.
11599

116100
### Features
117101

@@ -133,14 +117,13 @@ One nice feature of Python is its elegant syntax --- we'll see many examples lat
133117

134118
Elegant code might sound superfluous but in fact it's highly beneficial because it makes the syntax easy to read and easy to remember.
135119

136-
Remembering how to read from files, sort dictionaries and other such routine tasks means that you don't need to break your flow in order to hunt down correct syntax.
137-
138120
Closely related to elegant syntax is an elegant design.
139121

140122
Features like iterators, generators, decorators and list comprehensions make Python highly expressive, allowing you to get more done with less code.
141123

142124
[Namespaces](https://en.wikipedia.org/wiki/Namespace) improve productivity by cutting down on bugs and syntax errors.
143125

126+
144127
## Scientific Programming
145128

146129
```{index} single: scientific programming
@@ -150,19 +133,19 @@ Python has become one of the core languages of scientific computing.
150133

151134
It's either the dominant player or a major player in
152135

153-
* [machine learning and data science](https://github.com/ml-tooling/best-of-ml-python)
154-
* [astronomy](http://www.astropy.org/)
155-
* [chemistry](http://chemlab.github.io/chemlab/)
156-
* [computational biology](http://biopython.org/wiki/Main_Page)
157-
* [meteorology](https://pypi.org/project/meteorology/)
158-
* [natural language processing](https://www.nltk.org/)
159-
160-
Its popularity in economics is also beginning to rise.
136+
* AI, machine learning and data science
137+
* astronomy
138+
* chemistry
139+
* computational biology
140+
* meteorology
141+
* natural language processing
142+
* etc.
161143

162144
This section briefly showcases some examples of Python for scientific programming.
163145

164146
* All of these topics below will be covered in detail later on.
165147

148+
166149
### Numerical Programming
167150

168151
```{index} single: scientific programming; numeric
@@ -256,128 +239,6 @@ Other graphics libraries include
256239

257240
You can visit the [Python Graph Gallery](https://www.python-graph-gallery.com/) for more example plots drawn using a variety of libraries.
258241

259-
### Symbolic Algebra
260-
261-
It's useful to be able to manipulate symbolic expressions, as in Mathematica or Maple.
262-
263-
```{index} single: SymPy
264-
```
265-
266-
The [SymPy](http://www.sympy.org/) library provides this functionality from within the Python shell.
267-
268-
```{code-cell} python3
269-
from sympy import Symbol
270-
271-
x, y = Symbol('x'), Symbol('y') # Treat 'x' and 'y' as algebraic symbols
272-
x + x + x + y
273-
```
274-
275-
We can manipulate expressions
276-
277-
```{code-cell} python3
278-
expression = (x + y)**2
279-
expression.expand()
280-
```
281-
282-
solve polynomials
283-
284-
```{code-cell} python3
285-
from sympy import solve
286-
287-
solve(x**2 + x + 2)
288-
```
289-
290-
and calculate limits, derivatives and integrals
291-
292-
```{code-cell} python3
293-
from sympy import limit, sin, diff, integrate
294-
295-
limit(1 / x, x, 0)
296-
```
297-
298-
```{code-cell} python3
299-
limit(sin(x) / x, x, 0)
300-
```
301-
302-
```{code-cell} python3
303-
diff(sin(x), x)
304-
```
305-
306-
```{code-cell} python3
307-
integrate(sin(x) * x, x)
308-
```
309-
310-
The beauty of importing this functionality into Python is that we are working within a fully fledged programming language.
311-
312-
We can easily create tables of derivatives, generate LaTeX output, add that output to figures and so on.
313-
314-
### Statistics
315-
316-
Python's data manipulation and statistics libraries have improved rapidly over
317-
the last few years to tackle
318-
[specific problems in data science](https://ieeexplore.ieee.org/document/8757088).
319-
320-
#### Pandas
321-
322-
```{index} single: Pandas
323-
```
324-
325-
One of the most popular libraries for working with data is [pandas](http://pandas.pydata.org/).
326-
327-
Pandas is fast, efficient, flexible and well designed.
328-
329-
Here's a simple example, using some dummy data generated with Numpy's excellent
330-
`random` functionality.
331-
332-
```{code-cell} python3
333-
import pandas as pd
334-
np.random.seed(1234)
335-
336-
data = np.random.randn(5, 2) # 5x2 matrix of N(0, 1) random draws
337-
dates = pd.date_range('2010-12-28', periods=5)
338-
339-
df = pd.DataFrame(data, columns=('price', 'weight'), index=dates)
340-
print(df)
341-
```
342-
343-
```{code-cell} python3
344-
df.mean()
345-
```
346-
347-
348-
#### Other Useful Statistics and Data Science Libraries
349-
350-
```{index} single: statsmodels
351-
```
352-
353-
* [statsmodels](http://statsmodels.sourceforge.net/) --- various statistical routines
354-
355-
```{index} single: scikit-learn
356-
```
357-
358-
* [scikit-learn](http://scikit-learn.org/) --- Machine Learning in Python
359-
360-
```{index} single: PyTorch
361-
```
362-
363-
* [PyTorch](https://pytorch.org/) --- Deep learning framework in Python and other major competitors in the field including [TensorFlow](https://www.tensorflow.org/overview) and [Keras](https://keras.io/)
364-
365-
```{index} single: Pyro
366-
```
367-
368-
* [Pyro](https://pyro.ai/) and [PyStan](https://pystan.readthedocs.org/en/latest/) --- for Bayesian data analysis building on [Pytorch](https://pytorch.org/) and [stan](http://mc-stan.org/) respectively
369-
370-
```{index} single: lifelines
371-
```
372-
373-
* [lifelines](https://lifelines.readthedocs.io/en/latest/) --- for survival analysis
374-
375-
```{index} single: GeoPandas
376-
```
377-
378-
* [GeoPandas](https://geopandas.org/en/stable/) --- for spatial data analysis
379-
380-
381242
### Networks and Graphs
382243

383244
Python has many libraries for studying graphs.
@@ -423,128 +284,28 @@ nx.draw_networkx_nodes(g,
423284
plt.show()
424285
```
425286

426-
### Cloud Computing
427-
428-
```{index} single: cloud computing
429-
```
430-
431-
Running your Python code on massive servers in the cloud is becoming easier and easier.
432-
433-
```{index} single: cloud computing; google colab
434-
```
435-
436-
An excellent example of the portability of python in a cloud computing environment is [Google Colab](https://colab.research.google.com/). It hosts the Jupyter notebook on cloud servers with no pre-configuration necessary to run Python code using cloud servers.
437-
438-
439-
There are also commercial applications of cloud computing using Python:
440-
441-
```{index} single: cloud computing; anaconda enterprise
442-
```
443-
* [Anaconda Enterprise](https://www.anaconda.com/enterprise/)
444-
445-
```{index} single: cloud computing; AWS
446-
```
447-
448-
* [Amazon Web Services](https://aws.amazon.com/developer/language/python/?nc1=f_dr)
287+
### Other Scientific Libraries
449288

450-
```{index} single: cloud computing; Google Cloud
451-
```
452-
453-
* [Google Cloud](https://cloud.google.com/)
454-
455-
```{index} single: cloud computing; digital ocean
456-
```
457-
458-
* [Digital Ocean](https://www.digitalocean.com/)
459-
460-
461-
### Parallel Processing
462-
463-
```{index} single: parallel computing
464-
```
465-
466-
Apart from the cloud computing options listed above, you might like to consider
467-
468-
```{index} single: parallel computing; ipython
469-
```
470-
471-
* [Parallel computing through IPython clusters](https://ipyparallel.readthedocs.io/en/latest/).
472-
473-
474-
```{index} single: parallel computing; Dask
475-
```
476-
477-
* [Dask](https://docs.dask.org/en/stable/) parallelises PyData and Machine Learning in Python.
478-
479-
```{index} single: parallel computing; pycuda
480-
```
289+
Here's a short list of more important scientific libraries for Python.
481290

482-
* GPU programming through [JAX](https://jax.readthedocs.io/en/latest/notebooks/quickstart.html), [PyCuda](https://wiki.tiker.net/PyCuda), [PyOpenCL](https://documen.tician.de/pyopencl/), [Rapids](https://rapids.ai/), etc.
483-
484-
485-
Here is more about [recent developments](https://pasc22.pasc-conference.org/program/papers/) in high-performance computing (HPC) in scientific computing and [how HPC helps researchers in different fields](https://pasc22.pasc-conference.org/program/keynote-presentations/).
486-
487-
(intfc)=
488-
### Other Developments
489-
490-
There are many other interesting developments with scientific programming in Python.
491-
492-
Some representative examples include
493-
494-
```{index} single: scientific programming; Jupyter
495-
```
496-
497-
* [Jupyter](http://jupyter.org/) --- Python in your browser with interactive code cells, embedded images and other useful features.
498-
499-
```{index} single: scientific programming; Numba
500-
```
501-
502-
* [Numba](http://numba.pydata.org/) --- make Python run at the same speed as native machine code!
503-
504-
```{index} single: scientific programming; CVXPY
505-
```
506-
507-
* [CVXPY](https://www.cvxpy.org/) --- convex optimization in Python.
508-
509-
510-
```{index} single: scientific programming; PyTables
511-
```
512-
513-
* [PyTables](http://www.pytables.org) --- manage large data sets.
514-
515-
516-
```{index} single: scientific programming; scikit-image
517-
```
518-
519-
* [scikit-image](https://scikit-image.org/) and [OpenCV](https://opencv.org/) --- process and analyse scientific image data.
520-
521-
522-
```{index} single: scientific programming; mlflow
523-
```
524-
525-
* [FLAML](https://mlflow.org/docs/latest/index.html) --- automate machine learning and hyperparameter tuning.
526-
527-
528-
```{index} single: scientific programming; BeautifulSoup
529-
```
530-
531-
* [BeautifulSoup](https://www.crummy.com/software/BeautifulSoup/bs4/doc/) --- extract data from HTML and XML files.
532-
533-
```{index} single: scientific programming; PyInstaller
534-
```
535-
536-
* [PyInstaller](https://pyinstaller.org/en/stable/) --- create packaged app from python script.
537-
538-
## Learn More
539-
540-
* Browse some Python projects on [GitHub](https://github.com/trending?l=python).
541-
* Read more about [Python's history and rise in popularity](https://www.welcometothejungle.com/en/articles/btc-python-popular) and [version history](https://www.python.org/doc/versions/).
542-
* Have a look at [some of the Jupyter notebooks](http://nbviewer.jupyter.org/) people have shared on various scientific topics.
543-
544-
```{index} single: Python; PyPI
545-
```
291+
* [SymPy](http://www.sympy.org/) for symbolic algebra, including limits, derivatives and integrals
292+
* [pandas](http://pandas.pydata.org/) for data maniputation
293+
* [statsmodels](http://statsmodels.sourceforge.net/) for statistical routines
294+
* [scikit-learn](http://scikit-learn.org/) for machine learning
295+
* [JAX](https://github.com/google/jax) for automatic differentiation, accelerated linear algebra and GPU computing
296+
* [PyTorch](https://pytorch.org/) for deep learning
297+
* [Keras](https://keras.io/) for machine learning
298+
* [Pyro](https://pyro.ai/) and [PyStan](https://pystan.readthedocs.org/en/latest/) for Bayesian data analysis
299+
* [lifelines](https://lifelines.readthedocs.io/en/latest/) for survival analysis
300+
* [GeoPandas](https://geopandas.org/en/stable/) for spatial data analysis
301+
* [Dask](https://docs.dask.org/en/stable/) for parallelization
302+
* [Numba](http://numba.pydata.org/) for making Python run at the same speed as native machine code
303+
* [CVXPY](https://www.cvxpy.org/) for convex optimization
304+
* [PyTables](http://www.pytables.org) for managing large data sets
305+
* [scikit-image](https://scikit-image.org/) and [OpenCV](https://opencv.org/) for processing and analysing image data
306+
* [FLAML](https://mlflow.org/docs/latest/index.html) for automated machine learning and hyperparameter tuning
307+
* [BeautifulSoup](https://www.crummy.com/software/BeautifulSoup/bs4/doc/) for extracting data from HTML and XML files
546308

547-
* Visit the [Python Package Index](https://pypi.org/).
548-
* View some of the questions people are asking about Python on [Stackoverflow](http://stackoverflow.com/questions/tagged/python).
549-
* Keep up to date on what's happening in the Python community with the [Python subreddit](https://www.reddit.com:443/r/Python/).
550309

310+
In this lecture series we will learn how to use many of these libraries for
311+
scientific computing tasks in economics and finance.

0 commit comments

Comments
 (0)