Join Our 5-Week ML/AI Engineer Interview Bootcamp 🚀 led by ML Tech Leads at FAANGs

Back to Questions

218. Linear independence

easy
GeneralGeneral
senior

Linear independence is a core linear algebra concept used to tell whether a set of vectors contains any redundancy. In this task, you’ll implement a simple checker that decides if a list of vectors is linearly independent. Formally, a set of vectors {v1,…,vk}\{\mathbf{v}_1, \dots, \mathbf{v}_k\} is linearly independent if the equation:

c1v1+⋯+ckvk=0c_1 \mathbf{v}_1 + \dots + c_k \mathbf{v}_k = \mathbf{0}

has only the trivial solution c1=⋯=ck=0c_1 = \dots = c_k = 0.

Requirements

Implement the function

python

Rules:

  • Use the definition: vectors are linearly independent iff the only solution to (A\mathbf{c}=\mathbf{0}) is (\mathbf{c}=\mathbf{0}), where (A) has the vectors as columns.
  • Build matrix (A) from the input list and determine independence via rank: independent iff (\text{rank}(A)=k).
  • Return a single boolean (True/False).
  • Do not use symbolic math libraries or prebuilt “independence” helpers; rely on NumPy linear algebra (e.g., np.linalg.matrix_rank).

Example

python

Output:

python
Input Signature
ArgumentType
vectorsnp.ndarray
Output Signature
Return NameType
valuebool

Constraints

  • Use NumPy for calculation

  • Input is a NumPy array

  • Return a single boolean True/False

Hint 1

Use the property that a set of k vectors is linearly independent if and only if the matrix formed by them has rank equal to k.

Hint 2

np.linalg.matrix_rank(A) computes the rank (number of linearly independent rows or columns).

Hint 3

Check if np.linalg.matrix_rank(vectors) == len(vectors).

Roles
ML Engineer
AI Engineer
Companies
GeneralGeneral
Levels
senior
entry
Tags
linear-algebra
matrix-rank
numpy
25 people are solving this problem
Python LogoPython Editor
Ln 1, Col 1

Input Arguments

Edit values below to test with custom inputs

You need tolog in/sign upto run or submit