You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: lectures/about_py.md
+47-65Lines changed: 47 additions & 65 deletions
Original file line number
Diff line number
Diff line change
@@ -34,52 +34,58 @@ into R." -- Chris Wiggins
34
34
This lecture series will teach you to use Python for scientific computing, with
35
35
a focus on economics and finance.
36
36
37
-
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.
38
39
39
40
In this lecture we will
40
41
41
42
* introduce Python,
42
43
* showcase some of its abilities,
43
-
* discuss the connection between Python and AI,
44
44
* explain why Python is our favorite language for scientific computing, and
45
45
* point you to the next steps.
46
46
47
47
You do **not** need to understand everything you see in this lecture -- we will work through the details slowly later in the lecture series.
48
48
49
49
50
-
### Can't I Just Use ChatGPT?
50
+
### Can't I Just Use LLMs?
51
51
52
52
No!
53
53
54
-
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.
55
55
56
-
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.
57
57
58
-
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.
59
59
60
-
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.
61
61
62
-
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.
63
64
64
-
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.
65
67
66
68
67
69
### Isn't MATLAB Better?
68
70
69
71
No, no, and one hundred times no.
70
72
71
-
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.
72
75
73
-
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.
75
79
76
-
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.
77
82
78
-
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).
79
85
80
86
81
-
## What's Python?
82
87
88
+
## Introducing Python
83
89
84
90
[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).
85
91
@@ -92,13 +98,13 @@ This is important because it
92
98
* encourages reproducibility and [open science](https://en.wikipedia.org/wiki/Open_science).
93
99
94
100
95
-
96
101
### Common Uses
97
102
98
-
{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
99
105
100
-
* AI
101
-
* scientific computing
106
+
* AI and computer science
107
+
*other scientific computing
102
108
* communication
103
109
* web development
104
110
* CGI and graphical user interfaces
@@ -107,67 +113,55 @@ This is important because it
107
113
* multimedia
108
114
* etc.
109
115
110
-
It is used and supported extensively by tech firms including
116
+
It is used and supported extensively by large tech firms including
111
117
112
118
*[Google](https://www.google.com/)
113
119
*[OpenAI](https://openai.com/)
114
120
*[Netflix](https://www.netflix.com/)
115
121
*[Meta](https://opensource.fb.com/)
116
-
*[Dropbox](https://www.dropbox.com/)
117
122
*[Amazon](https://www.amazon.com/)
118
123
*[Reddit](https://www.reddit.com/)
119
124
* etc.
120
125
121
126
122
-
123
-
124
127
### Relative Popularity
125
128
126
-
Python is, without doubt, one of the [most popular programming languages](https://www.tiobe.com/tiobe-index/).
129
+
Python isone of the most -- if not the most -- [popular programming languages](https://www.tiobe.com/tiobe-index/).
127
130
128
131
Python 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.
129
132
130
-
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
133
134
134
-
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.
Pytorch is just one of several Python libraries for deep learning and AI.
139
143
140
-
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.
143
144
144
145
145
146
### Features
146
147
147
-
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.
148
151
149
152
It has a relatively small core language that is easy to learn.
150
153
151
-
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.
162
155
156
+
Python is flexible and pragmatic, supporting multiple programming styles (procedural, object-oriented, functional, etc.).
163
157
164
158
165
159
### Syntax and Design
166
160
167
161
```{index} single: Python; syntax and design
168
162
```
169
163
170
-
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.
171
165
172
166
To get a feeling for this, let's look at an example.
173
167
@@ -231,12 +225,9 @@ public class CSVReader {
231
225
This Java code opens an imaginary file called `data.csv` and computes the mean
232
226
of the values in the second column.
233
227
234
-
Even without knowing Java, you can see that the program is long and complex.
235
-
236
228
Here's Python code that does the same thing.
237
229
238
-
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.
0 commit comments