Linear Algebra is a key foundation to the field of machine learning and data science, from notations used to describe the operation of algorithms to the implementation of algorithms in code. Follow along and check the 14 most common Linear Algebra Interview Questions every ML engineer and data scientist shall brush before next daa science interview.
The invert of a square diagonal matrix exists if all entries of the diagonal are non-zero. If it is the case, the invert is obtained by replacing each element in the diagonal with its reciprocal.
Given a matrix A, we find its eigenvalues λ by solving the equation:
For example, given the following matrix,
we determine its eigenvalues in the following way:
Now the characteristic polynomial is:
The solutions of this equation and therefore the eigenvalues are then,
Ax = b is a system of linear equations expressed in matrix notation, in which:
The system Ax = b has a unique solution if and only if
where the matrix A|b is matrix A with b appended as an extra column.
α is the angle between the vectors.
θ is the angle between the vectors.
x and y orthogonal?Two vectors are said to be orthogonal if the dot product of them is equal to zero,
This is because the definition of the dot product:
where θ is the angle between the two vectors, therefore if x and y are orthogonal, the angle between them is 90 and cos(90) = 0.
We say that a matrix A is normal if where A* is the conjugate transpose of matrix A.
Prove equality for A:
Prove equality for B:
Consider the matrix:
We will compute inverse using the following equation: where adj(A) is the adjugate of matrix A. Now we follow the next steps:
Calculate the determinant of A:
Calculate the cofactor of each element:
Thus, the cofactor matrix is:
Given an nxn matrix A, to find its diagonal matrix D we must follow the next steps:
3 is not equal to n (the numbers of rows and columns of A), then the matrix is not diagonalizable, but if m = n then the diagonal matrix D is given by: 2x2 matrix?For an arbitrary A matrix, we can derive it's inverse by following the next steps:
There are different ways to measure the magnitude of vectors, the most common are:
L0 norm: Although it's not formally speaking a norm, it's often used as if was one. It corresponds to the total number of nonzero elements in a vector. For example, the L0 norm of the vector [0,2] is 1 because there is only one nonzero element.
L1 norm: Also known as Manhattan Distance, is the sum of absolute values of the components of the vector. For example, for some vector:
The L1 norm is calculated by:
L2 norm: Also known as the Euclidean norm, it is the shortest distance to go from one point to another. Using the same example as before, the L2 norm for the vector defined above is:
L-infinity norm: Gives the largest magnitude among each element of a vector. For example, having the vector X= [-6, 4, 2], the L-infinity norm is 6.
Given that we can associate each matrix with the quadratic equation zᵗMz, these kinds of matrix helps us to solve optimization problems. For example, a positive definite matrix M will imply a convex function, which guarantees the existence of the global minimum. This allows us to use the Hessian matrix to solve the optimization problem. Similar arguments also hold for negative definite matrices.
Broadcasting is a mechanism for relaxing elementwise operations according to the dimension requirements. We say that two matrices are compatible for broadcasting if the corresponding dimensions in each matrix (rows vs rows, columns vs columns) meet the following criteria:
1.The way that broadcasting works are by duplicating the smaller array so that it is the dimensionality and size as the larger array.
Initially, this method was developed for NumPy, but it has also been adopted more broadly in other numerical computational libraries, such as Theano, TensorFlow, and Octave.
An orthogonal matrix is a type of square matrix whose columns and rows are orthonormal unit vectors, e.g. perpendicular, and have a length or magnitude of 1. Formally, it's defined as follows:
Where Q is the orthogonal matrix, Qᵗ indicates the transpose of Q, and I is the identity matrix. From the above definition, we can see that
Therefore, the orthogonal matrix is preferred because they are computationally cheap and stable to calculate their inverse as simply their transpose.
The determinant is a scalar value that is a function of the entries of a square matrix. The determinant of a matrix A is denoted det(A), det A, or |A|. Geometrically, it can be viewed as the volume scaling factor of the linear transformation described by the matrix.
In the case of a 2 × 2 matrix the determinant is calculated following the next diagram:
That is, the determinant is equal to the product of the elements along the plus-labeled arrow minus the product of the elements along the minus-labeled arrow.
Similarly, for a 3 × 3 matrix A, its determinant is
Each determinant of a 2 × 2 matrix in the equation above is called a minor of the matrix A.
For an n × n matrix, the previous procedure is extended and provides a recursive definition for the determinant, known as a Laplace expansion.
In simple terms, a matrix is a grid of n × m (say, 3 × 3) numbers surrounded by brackets. We can add and subtract matrices of the same size, multiply one matrix with another as long as the sizes are compatible, and multiply an entire matrix by a constant.
A tensor is a generalization of matrices to N-dimensional space. That is, it could be a 1-D matrix (a vector), a 3-D matrix (something like a cube of numbers), or even a 0-D matrix (a single number), etc. The dimension of the tensor is called rank.
A tensor can be also seen as a mathematical entity that lives in a structure and interacts with other mathematical entities. If one transforms the other entities in the structure in a regular way, then the tensor obeys a related transformation rule. This dynamical property of a tensor is also a key to distinguish it from a mere matrix. For example, any rank-2 tensor can be represented as a matrix, but not every matrix is really a rank-2 tensor. The difference depends on the transformation rules that have been applied to the entire system.
Prepare for AI developer and engineer interviews with 19 answered OpenClaw questions covering Gateway architecture, channels, agent workspaces, memory, MCP, model failover, multi-agent routing, security, sandboxing, approvals, and remote operations....
Prepare for AI agent developer interviews with 15 Model Context Protocol (MCP) questions covering tools, resources, prompts, JSON-RPC, transports, roots, sampling, security, and practical MCP server design....
Amazone runs the internet as we know it. Amazon Web Services (AWS) offers a comprehensive suite of machine learning (ML) services that cater to various needs and expertise levels. Follow along and learn the 23 most common AWS machine-learning intervi...