Editor

Solve the Price Puzzle

Advanced · Write the code · from NumPy Linear Algebra: Dot Products, Inverses, and Eigenvalues

From the lesson: NumPy Linear Algebra: Dot Products, Inverses, and Eigenvalues

Linear algebra is the math behind machine learning, computer graphics, physics simulations, and data science. Every time a game rotates a 3D object, a search engine ranks pages, or a neural network makes a prediction, matrix operations are doing the heavy lifting.

Read the lesson

A store sells pens and notebooks. The prices are unknown.

  • 3 pens + 2 notebooks = $13
  • 1 pen + 4 notebooks = $17
  • Set up the coefficient matrix and the right-hand side vector, then use np.linalg.solve() to find the price of each item. Print the price of a pen and then the price of a notebook, each on a separate line, rounded to 2 decimal places.

    import numpy as np
    # Set up the system and solve

    More NumPy Linear Algebra exercises

    All Python exercises · 50 practice problems · Data Science & Machine Learning quiz