Python practice: NumPy Arrays & Vectorization

Chapter 17 · 8 questions · included in full access

  1. Question 1 · easy

    Create 1D NumPy array and multiply

    Import numpy as np. Create array prices = np.array([100.0, 200.0, 300.0]). Multiply by 1.18 to compute taxed, and print taxed:

    Solve it in your browser
  2. Question 2 · easy

    Inspect 2D matrix shape and size

    Given 2D array matrix = np.array([[10, 20, 30], [40, 50, 60]]), print matrix.shape on line 1 and matrix.size on line 2:

    Solve it in your browser
  3. Question 3 · easy

    Vectorized element-wise subtraction

    Given units = np.array([50, 80, 100]) and returns_arr = np.array([5, 10, 12]), compute net = units - returns_arr and print net:

    Solve it in your browser
  4. Question 4 · easy

    Compute array sum and mean

    Given sales = np.array([1200, 3400, 850, 4100]), print sales.sum() on line 1, and sales.mean() on line 2:

    Solve it in your browser
  5. Question 5 · easy

    Column-wise sum with axis=0

    Given 2D array grid = np.array([[10, 20], [30, 40]]), compute column-wise sum using grid.sum(axis=0) and print the result:

    Solve it in your browser
  6. Question 6 · easy

    Row-wise sum with axis=1

    Given 2D array grid = np.array([[10, 20], [30, 40]]), compute row-wise sum using grid.sum(axis=1) and print the result:

    Solve it in your browser
  7. Question 7 · medium

    Extract 2D sub-matrix slice

    Given mat = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]), slice rows 0:2 and columns 1:3 using mat[0:2, 1:3] and print:

    Solve it in your browser
  8. Question 8 · easy

    Scalar broadcasting multiplication

    Given units = np.array([10, 25, 40]), multiply by unit cost 45.0 to calculate costs and print costs:

    Solve it in your browser

These questions are part of full access.

The first chapters of every track are free. Full access is a one-time payment.

See pricing