Skip to content

Commit 803708c

Browse files
committed
quizzes: teacher notebooks were still .py
1 parent 243713b commit 803708c

12 files changed

+652
-637
lines changed

notebooks/quizzes/.teacher/QUIZ-1-numpy-basics-corrige-nb.py renamed to notebooks/quizzes/.teacher/QUIZ-1-numpy-basics-corrige-nb.md

Lines changed: 77 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,37 @@
1-
# -*- coding: utf-8 -*-
2-
# ---
3-
# jupyter:
4-
# jupytext:
5-
# cell_metadata_filter: all,-hidden,-heading_collapsed,-run_control,-trusted,-editable
6-
# formats: py:percent
7-
# notebook_metadata_filter: all, -jupytext.text_representation.jupytext_version,
8-
# -jupytext.text_representation.format_version,-language_info.version, -language_info.codemirror_mode.version,
9-
# -language_info.codemirror_mode,-language_info.file_extension, -language_info.mimetype,
10-
# -toc, -rise, -version
11-
# text_representation:
12-
# extension: .py
13-
# format_name: percent
14-
# kernelspec:
15-
# display_name: Python 3 (ipykernel)
16-
# language: python
17-
# name: python3
18-
# language_info:
19-
# name: python
20-
# nbconvert_exporter: python
21-
# pygments_lexer: ipython3
22-
# nbhosting:
23-
# title: basic numpy
24-
# ---
25-
26-
# %%
1+
---
2+
jupytext:
3+
text_representation:
4+
extension: .md
5+
format_name: myst
6+
encoding: '# -*- coding: utf-8 -*-'
7+
kernelspec:
8+
display_name: Python 3 (ipykernel)
9+
language: python
10+
name: python3
11+
language_info:
12+
name: python
13+
nbconvert_exporter: python
14+
pygments_lexer: ipython3
15+
nbhosting:
16+
title: basic numpy
17+
---
18+
19+
```{code-cell} ipython3
2720
import numpy as np
2821
import pandas as pd
2922
import matplotlib.pyplot as plt
3023
import seaborn as sns
24+
```
3125

32-
# %% [markdown]
33-
# # data loading
26+
# data loading
3427

35-
# %% [markdown]
36-
# Let's load a dataset on rain precipitations on Seattle on 2014
28+
+++
29+
30+
Let's load a dataset on rain precipitations on Seattle on 2014
31+
32+
```{code-cell} ipython3
33+
:lines_to_next_cell: 2
3734
38-
# %%
3935
# we download the file from Internet and save it
4036
# easiest way, we can pass a URL to read_csv (or a local file)
4137
URL = "http://www-sop.inria.fr/members/Arnaud.Legout/formationPython/Exos/Seattle2014.csv"
@@ -54,79 +50,87 @@
5450
# rainfall is an array of precipitation per day
5551
# for each day of 2014
5652
# rainfall = pd.read_csv('Seattle2014.csv')['PRCP'].to_numpy()
53+
```
5754

55+
## Let's visualize
5856

59-
# %% [markdown]
60-
# ## Let's visualize
57+
+++
6158

62-
# %% [markdown]
63-
# **[assignement]**: plot the amount of rain (in mm) over time; make sure you put a proper label on both axes, and on the global figure
64-
#
59+
**[assignement]**: plot the amount of rain (in mm) over time; make sure you put a proper label on both axes, and on the global figure
6560

66-
# %%
61+
```{code-cell} ipython3
6762
# your code here
63+
```
64+
65+
```{code-cell} ipython3
66+
:tags: []
6867
69-
# %% tags=[]
7068
# prune-cell
7169
7270
plt.plot(rainfall)
7371
plt.xlabel("days")
7472
plt.ylabel("mm")
7573
plt.title("Rainy days in 2014 at Seattle")
74+
```
75+
76+
## Let's answer the following questions
7677

77-
# %% [markdown]
78-
# ## Let's answer the following questions
78+
+++
7979

80-
# %% [markdown]
81-
# **What is the shape and dype of the ndarray?**
80+
**What is the shape and dype of the ndarray?**
8281

83-
# %%
82+
```{code-cell} ipython3
8483
# your code here
84+
```
8585

86-
# %%
86+
```{code-cell} ipython3
8787
# prune-cell
8888
print(f"{rainfall.shape=}\n{rainfall.dtype=}")
89+
```
8990

90-
# %% [markdown]
91-
# **How many rainy days?**
91+
**How many rainy days?**
9292

93-
# %%
93+
```{code-cell} ipython3
9494
# your code here
95+
```
9596

96-
# %%
97+
```{code-cell} ipython3
9798
# prune-cell
9899
rainy_days = np.sum(rainfall > 0)
99100
print(f"{rainy_days=} days")
101+
```
100102

101-
# %% [markdown]
102-
# **Average precipitation on the year?**
103+
**Average precipitation on the year?**
103104

104-
# %%
105+
```{code-cell} ipython3
105106
# your code here
107+
```
106108

107-
# %%
109+
```{code-cell} ipython3
108110
# prune-cell
109111
ave_precip_year = np.mean(rainfall)
110112
print(f"{ave_precip_year=:.2f}mm")
113+
```
111114

112-
# %% [markdown]
113-
# **Average precipitation on the rainy days?**
115+
**Average precipitation on the rainy days?**
114116

115-
# %%
117+
```{code-cell} ipython3
116118
# your code here
119+
```
117120

118-
# %%
121+
```{code-cell} ipython3
119122
# prune-cell
120123
ave_precip_rainy = np.mean(rainfall[rainfall > 0])
121124
print(f"{ave_precip_rainy=:.2f}mm")
125+
```
122126

123-
# %% [markdown]
124-
# **Mean precipitation on January?**
127+
**Mean precipitation on January?**
125128

126-
# %%
129+
```{code-cell} ipython3
127130
# your code here
131+
```
128132

129-
# %%
133+
```{code-cell} ipython3
130134
# prune-cell
131135
132136
# let's build expressive masks
@@ -137,23 +141,24 @@
137141
# mean precipitation on January
138142
mean_jan = np.mean(rainfall[january])
139143
print(f"{mean_jan=:.2f}mm")
144+
```
140145

141-
# %% [markdown]
142-
# **Mean precipitation on January on the rainy days?**
146+
**Mean precipitation on January on the rainy days?**
143147

144-
# %%
148+
```{code-cell} ipython3
145149
# your code here
150+
```
146151

147-
# %%
152+
```{code-cell} ipython3
148153
# prune-cell
149154
150155
mean_jan_rainy = np.mean(rainfall[january & rainy])
151156
print(f"{mean_jan_rainy=:.2f}mm")
157+
```
152158

153-
# %% [markdown]
154-
# # A transition to pandas
159+
# A transition to pandas
155160

156-
# %%
161+
```{code-cell} ipython3
157162
# But in practice we don’t do that. Here is what we do…
158163
# We start to convert to a pandas Series
159164
s = pd.Series(rainfall)
@@ -164,11 +169,12 @@
164169
165170
# possibly resample per month to get the total monthly rain
166171
s = s.resample('m').max()
172+
```
167173

168-
# %%
174+
```{code-cell} ipython3
169175
# then plot
170176
171-
# %matplotlib ipympl
177+
%matplotlib ipympl
172178
173179
s.plot.bar()
174180
plt.xlabel('month')
@@ -177,6 +183,6 @@
177183
fig = plt.gcf()
178184
fig.autofmt_xdate()
179185
# plt.show() # if in a terminal
186+
```
180187

181-
# %% [markdown]
182-
# ***
188+
***

0 commit comments

Comments
 (0)