@@ -34,52 +34,58 @@ into R." -- Chris Wiggins
3434This lecture series will teach you to use Python for scientific computing, with
3535a focus on economics and finance.
363637-The series is aimed at Python novices, although experienced users will also find useful content in later lectures.
37+The series is aimed at Python novices, although experienced users will also find
38+useful content in later lectures.
38393940In this lecture we will
40414142* introduce Python,
4243* showcase some of its abilities,
43-* discuss the connection between Python and AI,
4444* explain why Python is our favorite language for scientific computing, and
4545* point you to the next steps.
46464747You do **not** need to understand everything you see in this lecture -- we will work through the details slowly later in the lecture series.
4848494950-### Can't I Just Use ChatGPT?
50+### Can't I Just Use LLMs?
51515252No!
535354-It's tempting to think that in the age of AI we don't need to learn how to code.
54+Of course it's tempting to think that in the age of AI we don't need to learn how to code.
555556-And it's true that AIs like [ChatGPT](https://chatgpt.com/) and other LLMs are wonderful productivity tools for coders.
56+And yes, we like to be lazy too sometimes.
575758-In fact an AI can be a great companion for these lectures -- try copy-pasting some code from this series and ask the AI to explain it to you.
58+In addition, we agree that AIs are outstanding productivity tools for coders.
595960-AIs will certainly help you write pieces of code that you can combine.
60+But AIs cannot reliably solve new problems that they haven't seen before.
616162-But AIs cannot completely and reliably solve a new problem that they haven't seen before!
62+You will need to be the architect and the supervisor -- and for these tasks you need to
63+be able to read, write, and understand computer code.
636464-You will need to be the supervisor -- and for that you need to be able to read, write, and understand computer code.
65+Having said that, a good LLM is a useful companion for these lectures -- try copy-pasting some
66+code from this series and asking for an explanation.
656766686769### Isn't MATLAB Better?
68706971No, no, and one hundred times no.
707271-For almost all modern problems, Python's scientific libraries are now far in advance of MATLAB's capabilities.
73+Nirvana was great (and Soundgarden [was better](https://www.youtube.com/watch?v=3mbBbFH9fAg&list=RD3mbBbFH9fAg)) but
74+it's time to move on from the '90s.
727573-We will explain the benefits of Python's libraries throughout this lecture
74-series, as well as in our later series on [JAX](https://jax.quantecon.org/intro.html).
76+For most modern problems, Python's scientific libraries are now far in advance of MATLAB's capabilities.
77+78+This is particularly the case in fast-growing fields such as deep learning and reinforcement learning.
757976-We will also explain how Python's elegant design helps you write clean, efficient code.
80+Moreover, all major LLMs are more proficient at writing Python code than MATLAB
81+code.
778278-On top of these features, Python is more widely used, with a huge and helpful community, and free!
83+We will discuss relative merits of Python's libraries throughout this lecture
84+series, as well as in our later series on [JAX](https://jax.quantecon.org/intro.html).
7985808681-## What's Python?
828788+## Introducing Python
83898490[Python](https://www.python.org) is a general-purpose programming language conceived in 1989 by [Guido van Rossum](https://en.wikipedia.org/wiki/Guido_van_Rossum).
8591@@ -92,13 +98,13 @@ This is important because it
9298* encourages reproducibility and [open science](https://en.wikipedia.org/wiki/Open_science).
93999410095-96101### Common Uses
9710298-{index}`Python <single: Python; common uses>` is a general-purpose language used in almost all application domains, including
103+{index}`Python <single: Python; common uses>` is a general-purpose language used
104+in almost all application domains, including
99105100-* AI
101-* scientific computing
106+* AI and computer science
107+* other scientific computing
102108* communication
103109* web development
104110* CGI and graphical user interfaces
@@ -107,67 +113,55 @@ This is important because it
107113* multimedia
108114* etc.
109115110-It is used and supported extensively by tech firms including
116+It is used and supported extensively by large tech firms including
111117112118* [Google](https://www.google.com/)
113119* [OpenAI](https://openai.com/)
114120* [Netflix](https://www.netflix.com/)
115121* [Meta](https://opensource.fb.com/)
116-* [Dropbox](https://www.dropbox.com/)
117122* [Amazon](https://www.amazon.com/)
118123* [Reddit](https://www.reddit.com/)
119124* etc.
120125121126122-123-124127### Relative Popularity
125128126-Python is, without doubt, one of the [most popular programming languages](https://www.tiobe.com/tiobe-index/).
129+Python is one of the most -- if not the most -- [popular programming languages](https://www.tiobe.com/tiobe-index/).
127130128131Python libraries like [pandas](https://pandas.pydata.org/) and [Polars](https://pola.rs/) are replacing familiar tools like Excel and VBA as an essential skill in the fields of finance and banking.
129132130-Moreover, Python is extremely popular within the scientific community -- especially AI
131-132-The following chart, produced using Stack Overflow Trends, provides some evidence.
133+Moreover, Python is extremely popular within the scientific community -- especially those connected to AI
133134134-It shows the popularity of a Python AI library called [PyTorch](https://pytorch.org/) relative to MATLAB.
135+For example, the following chart from Stack Overflow Trends shows how the
136+popularity of a single Python deep learning library
137+([PyTorch](https://pytorch.org/)) has grown over the last few years.
135138136139137140```{figure} /_static/lecture_specific/about_py/pytorch_vs_matlab.png
138141```
142+Pytorch is just one of several Python libraries for deep learning and AI.
139143140-The chart shows that MATLAB's popularity has faded, while PyTorch is growing rapidly.
141-142-Moreover, PyTorch is just one of the thousands of Python libraries available for scientic computing.
143144144145145146### Features
146147147-Python is a [high-level language](https://en.wikipedia.org/wiki/High-level_programming_language), which means it is relatively easy to read, write and debug.
148+Python is a [high-level
149+language](https://en.wikipedia.org/wiki/High-level_programming_language), which
150+means it is relatively easy to read, write and debug.
148151149152It has a relatively small core language that is easy to learn.
150153151-This core is supported by many libraries, which you can learn to use as required.
152-153-Python is very beginner-friendly
154-155-* suitable for students learning programming
156-* used in many undergraduate and graduate programs
157-158-Other features of Python:
159-160-* multiple programming styles are supported (procedural, object-oriented, functional, etc.)
161-* [interpreted](https://en.wikipedia.org/wiki/Interpreter_(computing)) rather than [compiled](https://en.wikipedia.org/wiki/Compiler) ahead of time.
154+This core is supported by many libraries, which can be studied as required.
162155156+Python is flexible and pragmatic, supporting multiple programming styles (procedural, object-oriented, functional, etc.).
163157164158165159### Syntax and Design
166160167161```{index} single: Python; syntax and design
168162```
169163170-One reason for Python's popularity is its simple and elegant design --- we'll see many examples later on.
164+One reason for Python's popularity is its simple and elegant design.
171165172166To get a feeling for this, let's look at an example.
173167@@ -231,12 +225,9 @@ public class CSVReader {
231225This Java code opens an imaginary file called `data.csv` and computes the mean
232226of the values in the second column.
233227234-Even without knowing Java, you can see that the program is long and complex.
235-236228Here's Python code that does the same thing.
237229238-Even if you don't yet know Python, you can see that the code is simpler and
239-easier to read.
230+Even if you don't yet know Python, you can see that the code is far simpler and easier to read.
240231241232```{code-cell} python3
242233:tags: [skip-execution]
@@ -256,20 +247,14 @@ print(f"Average: {total / count if count else 'No valid data'}")
256247257248```
258249259-The simplicity of Python and its neat design are a big factor in its popularity.
260250261251262252### The AI Connection
263253264-Unless you have been living under a rock and avoiding all contact with the
265-modern world, you will know that AI is rapidly advancing.
266-267-AI is already remarkably good at helping you write code, as discussed above.
268-269-No doubt AI will take over many tasks currently performed by humans,
270-just like other forms of machinery have done over the past few centuries.
254+AI is in the process of taking over many tasks currently performed by humans,
255+just as other forms of machinery have done over the past few centuries.
271256272-Python is playing a huge role in the advance of AI and machine learning.
257+Moreover, Python is playing a huge role in the advance of AI and machine learning.
273258274259This means that tech firms are pouring money into development of extremely
275260powerful Python libraries.
@@ -288,9 +273,7 @@ These lectures will explain how.
288273289274We have already discussed the importance of Python for AI, machine learning and data science
290275291-Let's take a look at the role of Python in other areas of scientific computing.
292-293-Python is either the dominant player or a major player in
276+Python is also one of the dominant players in
294277295278* astronomy
296279* chemistry
@@ -305,7 +288,6 @@ operations research -- which were previously dominated by MATLAB / Excel / STATA
305288This section briefly showcases some examples of Python for general scientific programming.
306289307290308-309291### NumPy
310292311293```{index} single: scientific programming; numeric
@@ -379,6 +361,8 @@ However, you should still learn NumPy first because
379361* libraries like JAX directly extend NumPy functionality and hence are easier to
380362 learn when you already know NumPy.
381363364+This lecture series will provide you with extensive background in NumPy.
365+382366### SciPy
383367384368The [SciPy](http://www.scipy.org) library is built on top of NumPy and provides additional functionality.
@@ -453,7 +437,7 @@ You can visit the [Python Graph Gallery](https://www.python-graph-gallery.com/)
453437454438### Networks and Graphs
455439456-The study of networks and graphs becoming an important part of scientific work
440+The study of [networks](https://networks.quantecon.org/) is becoming an important part of scientific work
457441in economics, finance and other fields.
458442459443For example, we are interesting in studying
@@ -463,8 +447,6 @@ For example, we are interesting in studying
463447* friendship and social networks
464448* etc.
465449466-(We have a [book on economic networks](https://networks.quantecon.org/) if you would like to learn more.)
467-468450Python has many libraries for studying networks and graphs.
469451470452```{index} single: NetworkX
@@ -530,7 +512,7 @@ mentioned above.
530512* [Dask](https://docs.dask.org/en/stable/) for parallelization
531513* [Numba](http://numba.pydata.org/) for making Python run at the same speed as native machine code
532514* [CVXPY](https://www.cvxpy.org/) for convex optimization
533-* [scikit-image](https://scikit-image.org/) and [OpenCV](https://opencv.org/) for processing and analysing image data
515+* [scikit-image](https://scikit-image.org/) and [OpenCV](https://opencv.org/) for processing and analyzing image data
534516* [BeautifulSoup](https://www.crummy.com/software/BeautifulSoup/bs4/doc/) for extracting data from HTML and XML files
535517536518