26/34
Part 8 of 8 · Follow-upsLearn and do

What interviewers ask next

Why processes, and how many: lead with whether the work holds the GIL

Say first whether the work holds the GIL. Then the start-up and pickling cost. Then about one process per core for computing. The numbers are in the section on threads and processes.

Follow-up: a blur reads the rows next to it, so each band needs an overlap

The practice problem has no step like this. A blur is the likely follow-up to level 4.

def smooth(table):
    out = []
    for i in range(len(table)):
        # the row above, this row, the row below
        near = table[max(0, i - 1):i + 2]
        out.append([sum(column) // len(near) for column in zip(*near)])
    return out


S = [[0], [30], [0], [30], [0], [30]]
print(smooth(S))
print(smooth_in_bands(S, 2, overlap=0))
print(smooth_in_bands(S, 2, overlap=1))
[[15], [10], [20], [10], [20], [15]]
[[15], [15], [15], [15], [15], [15]]
[[15], [10], [20], [10], [20], [15]]

smooth turns each value into the mean, rounded down, of itself and its neighbors above and below, so each output row reads up to three input rows. A blur on an image is the same kind of step. It isn't row-local, so the groupby split runs it on the whole table.

Predict

smooth reads one row above and one below. Bands of 2 rows: how many extra rows must each band read on each side?

Pick an answer above to see the rest