Course review10 questions
Questions from the whole course
Each question comes from one lesson of Python for AI, and they are mixed, so you meet each idea away from its lesson. A wrong answer says why, and takes you back to that lesson.
Review
10 questions from across the course. Answer as often as you like.
1 of 10
From From a notebook to a script
A file total.py holds prices = [12, 8, 20] and, on its last line, sum(prices). In a notebook cell, these lines show 40. What does python total.py show?
2 of 10
From PyTorch tensors and their shapes
A batch of 8 digits, with a side for the channel. What does this print?
import torch
from sklearn import datasets
imgs = datasets.load_digits().images
x = torch.tensor(imgs[:8]).float()
x = x.reshape(8, 1, 8, 8)
conv = torch.nn.Conv2d(1, 4, 3)
out = conv(x)
print(out.shape)3 of 10
From Plotting to see data
The masses go from 2,700 to 6,300 grams. plt.hist(mass) cuts them into ten bins of the same width. How wide is each bin?
4 of 10
From Lists, loops and if
The spam filter: scores = [9, 2, 7], then for score in scores:, and under it if score > 5: with one print line. How many lines does it print?
5 of 10
From Calling an API
print(r.status_code) shows 401. Then info["downloads"] stops with KeyError: 'downloads'. What happened?
6 of 10
From Tables with pandas
mass is the table's body_mass_g column, one mass for each penguin. What does mass > 4500 give?
7 of 10
From Classes, just enough
Two taxis from one class. What does this print?
class Taxi:
def __init__(self, rate):
self.rate = rate
def price(self, km):
return self.rate * km
cheap = Taxi(2)
fast = Taxi(3)
print(cheap.price(4))8 of 10
From Your first lines of Python
cats = "7" and dogs = 2. What happens when Python runs total = cats + dogs?
9 of 10
Four penguins, two measurements each, and their species. What does this print?
from sklearn import tree
X = [[39, 18], [46, 13], [50, 19], [38, 17]]
y = ["Adelie", "Gentoo", "Chinstrap", "Adelie"]
model = tree.DecisionTreeClassifier()
model.fit(X, y)
kinds = model.predict(X)
print(kinds.shape)10 of 10
From Vectorization and broadcasting
extra has one number for each test. What does this print?
import numpy as np
scores = np.array([[7, 5, 8, 6], [9, 6, 7, 8], [4, 8, 6, 5]])
extra = np.array([0, 2, 0, 1])
new = scores + extra
print(new[1])