Run NumPy Online

NumPy Matrix Multiplication

Matrix multiplication combines rows from the first matrix with columns from the second matrix.

What is NumPy Matrix Multiplication?

Matrix multiplication combines rows from the first matrix with columns from the second matrix.

Multiply two matrices online with NumPy matmul and the @ operator.

When should you use it?

  • Perform numerical operations on many values at once.
  • Process arrays, matrices, and scientific data efficiently.
  • Prepare data for data science and machine learning.

Example code

Run code →
main.py
import numpy as np

left = np.array([[1, 2], [3, 4]])
right = np.array([[5, 6], [7, 8]])

product = left @ right
print(product)

Expected output

[[19 22]
 [43 50]]

How it works

The @ operator performs matrix multiplication. It differs from the * operator, which multiplies matching elements.

Change the values and run the program in the CodeUtility online Python compiler without installing Python locally.

Practice exercises

Modify the runnable example with the exercises below to build understanding beyond copying the result.

  1. Change the input shape and dtype.
  2. Try negative, floating-point, and missing values.
  3. Apply the operation to larger multidimensional arrays and measure performance.
Run in Python IDE →