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

Back to Questions

193. Orthogonality

easy
GeneralGeneral
senior

Orthogonality is a core linear-algebra concept used in ML to detect independence, remove redundancy, and measure similarity. In this task, you’ll implement a simple orthogonality checker for two vectors using the dot product.

x⊥y    ⟺    x⊤y=∑i=1nxiyi=0x \perp y \;\;\Longleftrightarrow\;\; x^\top y = \sum_{i=1}^{n} x_i y_i = 0

Requirements

Implement the function:

python

Rules:

  • Compute the dot product manually or via NumPy basic ops (no prebuilt distance/similarity helpers).
  • Use tol to handle floating-point error: return True if abs(dot) <= tol.
  • Return a single boolean value.
  • Keep it as a single Python function using only NumPy + built-in libraries.
  • Don’t print; just return.

Example

python

Output:

python
Input Signature
ArgumentType
xnp.ndarray
ynp.ndarray
tolfloat
Output Signature
Return NameType
valuebool

Constraints

  • Use NumPy; no similarity/distance helpers

  • Return boolean; no printing

  • Use tolerance: abs(dot) <= tol

Hint 1

Orthogonality means the dot product is zero: compute (\sum_i x_i y_i).

Hint 2

Use np.dot(x, y) to get the dot product.

Hint 3

Use tolerance for floating-point error: return abs(dot_val) <= tol.

Roles
ML Engineer
AI Engineer
Companies
GeneralGeneral
Levels
senior
entry
Tags
dot-product
orthogonality
numerical-tolerance
numpy
44 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