Python practice: NumPy Arrays & Vectorization
Chapter 17 · 8 questions · included in full access
Question 1 · easy
Create 1D NumPy array and multiply
Solve it in your browserImport
numpy as np. Create arrayprices = np.array([100.0, 200.0, 300.0]). Multiply by1.18to computetaxed, and printtaxed:Question 2 · easy
Inspect 2D matrix shape and size
Solve it in your browserGiven 2D array
matrix = np.array([[10, 20, 30], [40, 50, 60]]), printmatrix.shapeon line 1 andmatrix.sizeon line 2:Question 3 · easy
Vectorized element-wise subtraction
Solve it in your browserGiven
units = np.array([50, 80, 100])andreturns_arr = np.array([5, 10, 12]), computenet = units - returns_arrand printnet:Question 4 · easy
Compute array sum and mean
Solve it in your browserGiven
sales = np.array([1200, 3400, 850, 4100]), printsales.sum()on line 1, andsales.mean()on line 2:Question 5 · easy
Column-wise sum with axis=0
Solve it in your browserGiven 2D array
grid = np.array([[10, 20], [30, 40]]), compute column-wise sum usinggrid.sum(axis=0)and print the result:Question 6 · easy
Row-wise sum with axis=1
Solve it in your browserGiven 2D array
grid = np.array([[10, 20], [30, 40]]), compute row-wise sum usinggrid.sum(axis=1)and print the result:Question 7 · medium
Extract 2D sub-matrix slice
Solve it in your browserGiven
mat = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]), slice rows0:2and columns1:3usingmat[0:2, 1:3]and print:Question 8 · easy
Scalar broadcasting multiplication
Solve it in your browserGiven
units = np.array([10, 25, 40]), multiply by unit cost45.0to calculatecostsand printcosts:
These questions are part of full access.
The first chapters of every track are free. Full access is a one-time payment.
See pricing