NumPy gives you np.dot(), @, and np.linalg for linear algebra calculations. Matrix multiplication, inverse, determinant, solving equations, and more are all easy to compute in Python. This is foundational stuff for data science, machine learning, computer graphics, and engineering calculations.
import numpy as np
A = np.array([
[1, 2],
[3, 4]
])
B = np.array([
[5, 6],
[7, 8]
])
matrix_product = A @ B
determinant = np.linalg.det(A)
print("Matrix multiplication:
", matrix_product)
print("Determinant:", determinant)A @ B performs matrix multiplication, not element-wise multiplication. np.linalg.det(A) computes the determinant of matrix A. For matrix multiplication, A's column count has to match B's row count.
Matrix multiplication: [[19 22] [43 50]] Determinant: -2.0000000000000004Info
If you want element-wise multiplication, use A * B. If you want matrix multiplication, use A @ B or np.dot(A, B). Don't mix the two up.