Naar hoofdinhoud
πŸ”’ Voorbeeldmodus. De eerste vijftien Foundations-lessen zijn gratis; deze is Pro. Start een 7-daagse trial om de editor, AI-hints en de rest van het curriculum te ontgrendelen. Kaart vereist, op elk moment opzegbaar in Dashboard.Start 7-daagse trial β†’
⚑
← Cursussenβ€ΊSenior Deep-DivesModule 2 Β· CPython performance Β· Recapβ€ΊNumPy vectorisatiepatronenpredict47 / 161
+125 XP
Opdracht🌐 shown in EN
πŸ“ **Question:** Predict the exact output. Four vectorization patterns in one trace: (1) scalar broadcast \`a * 2\`, (2) scalar add on a 2D matrix, (3) row-broadcast \`m + row\` where the 1D row stretches across both rows of the matrix, (4) boolean mask \`a[a > 2]\`. \`.tolist()\` is used everywhere to keep output stable across NumPy versions. πŸ“‹ Pick the right answer. πŸ’‘ **Hint:** Re-read the theory above if unsure.
Voorspel uitvoer

Lees de code zorgvuldig

import numpy as np


a = np.array([1, 2, 3, 4])
b = a * 2
print(b.tolist())

m = np.array([[1, 2], [3, 4]])
print((m + 10).tolist())

row = np.array([10, 20])
print((m + row).tolist())

mask = a > 2
print(a[mask].tolist())
print(int(np.sum(a)))

Wat zal het programma uitprinten? Schrijf hier: